[cfe-commits] r59331 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def include/clang/Parse/DeclSpec.h lib/Parse/DeclSpec.cpp lib/Parse/ParseDecl.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp test/Parser/cxx-class.cpp test/SemaCXX/class.cpp www/cxx_status.html

Chris Lattner clattner at apple.com
Sun Nov 16 11:12:23 PST 2008


On Nov 14, 2008, at 3:42 PM, Sebastian Redl wrote:

> Author: cornedbee
> Date: Fri Nov 14 17:42:31 2008
> New Revision: 59331
>
> URL: http://llvm.org/viewvc/llvm-project?rev=59331&view=rev
> Log:
> Implement parsing and semantic checking of the 'mutable' keyword.
> Thanks to Doug for the review. Actual effects of mutable to follow.

Cool, two minor things:

> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Nov 14 17:42:31 2008
> @@ -1103,7 +1104,12 @@
>     case DeclSpec::SCS_auto:           SC = VarDecl::Auto; break;
>     case DeclSpec::SCS_register:       SC = VarDecl::Register; break;
>     case DeclSpec::SCS_private_extern: SC = VarDecl::PrivateExtern;  
> break;
> -    }
> +    case DeclSpec::SCS_mutable:
> +      // mutable can only appear on non-static class members, so  
> it's always
> +      // an error here
> +      Diag(D.getIdentifierLoc(), diag::err_mutable_nonmember);
> +      InvalidDecl = true;
> +    }

Please use an explicit break here, even though it isn't strictly needed.

> +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Nov 14 17:42:31 2008
> @@ -425,14 +425,44 @@
>   Expr *Init = static_cast<Expr*>(InitExpr);
>   SourceLocation Loc = D.getIdentifierLoc();
>
> +  bool isFunc = D.isFunctionDeclarator();
> +
>   // C++ 9.2p6: A member shall not be declared to have automatic  
> storage
>   // duration (auto, register) or with the extern storage-class- 
> specifier.
> +  // C++ 7.1.1p8: The mutable specifier can be applied only to  
> names of class
> +  // data members and cannot be applied to names declared const or  
> static,
> +  // and cannot be applied to reference members.
>   switch (DS.getStorageClassSpec()) {
>     case DeclSpec::SCS_unspecified:
>     case DeclSpec::SCS_typedef:
>     case DeclSpec::SCS_static:
>       // FALL THROUGH.
>       break;
> +    case DeclSpec::SCS_mutable:
> +      if (isFunc) {
> +        if (DS.getStorageClassSpecLoc().isValid())
> +          Diag(DS.getStorageClassSpecLoc(),
> +               diag::err_mutable_function);
> +        else
> +          Diag(DS.getThreadSpecLoc(),
> +               diag::err_mutable_function);
> +        D.getMutableDeclSpec().ClearStorageClassSpecs();

How does this work for things like:

   mutable int Y(), X;
or:
   mutable int &Y, X;

I guess it isn't the end of the world :), but it seems that it could  
cause spurious diagnostics in these cases by removing mutability from  
X.  Is it possible to recover by eliminating mutable from just Y?

-Chris




More information about the cfe-commits mailing list