[cfe-commits] r67717 - in /cfe/trunk: include/clang/AST/DeclBase.h lib/AST/DeclBase.cpp lib/Sema/SemaDecl.cpp test/SemaCXX/nested-name-spec.cpp

Anders Carlsson andersca at mac.com
Wed Mar 25 16:38:07 PDT 2009


Author: andersca
Date: Wed Mar 25 18:38:06 2009
New Revision: 67717

URL: http://llvm.org/viewvc/llvm-project?rev=67717&view=rev
Log:
Tighten the setAccess assert. We now allow AS_none if the decl contex is not a C++ record decl. 

Also, fix fallout from the change.

Modified:
    cfe/trunk/include/clang/AST/DeclBase.h
    cfe/trunk/lib/AST/DeclBase.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/nested-name-spec.cpp

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=67717&r1=67716&r2=67717&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Wed Mar 25 18:38:06 2009
@@ -138,6 +138,12 @@
   /// the implementation rather than explicitly written by the user.
   bool Implicit : 1;
 
+#ifndef NDEBUG
+  void CheckAccessDeclContext() const;
+#else
+  void CheckAccessDeclContext() const { }
+#endif
+  
 protected:
   /// Access - Used by C++ decls for the access specifier.
   // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum
@@ -148,7 +154,7 @@
     : NextDeclarator(0), NextDeclInScope(0), 
       DeclCtx(reinterpret_cast<uintptr_t>(DC)), 
       Loc(L), DeclKind(DK), InvalidDecl(0),
-      HasAttrs(false), Implicit(false) {
+      HasAttrs(false), Implicit(false), Access(AS_none) {
     if (Decl::CollectingStats()) addDeclKind(DK);
   }
 
@@ -175,11 +181,15 @@
                          const_cast<const Decl*>(this)->getDeclContext());
   }
 
-  void setAccess(AccessSpecifier AS) { 
-    assert(AS != AS_none && "Can't set access to none");
+  void setAccess(AccessSpecifier AS) {
     Access = AS; 
+    CheckAccessDeclContext();
+  }
+  
+  AccessSpecifier getAccess() const { 
+    CheckAccessDeclContext();
+    return AccessSpecifier(Access); 
   }
-  AccessSpecifier getAccess() const { return AccessSpecifier(Access); }
 
   bool hasAttrs() const { return HasAttrs; }
   void addAttr(Attr *attr);

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=67717&r1=67716&r2=67717&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Wed Mar 25 18:38:06 2009
@@ -272,6 +272,14 @@
   }
 }
 
+#ifndef NDEBUG
+void Decl::CheckAccessDeclContext() const {
+  assert((Access != AS_none || !isa<CXXRecordDecl>(getDeclContext())) &&
+         "Access specifier is AS_none inside a record decl");
+}
+
+#endif
+
 //===----------------------------------------------------------------------===//
 // DeclContext Implementation
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=67717&r1=67716&r2=67717&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Mar 25 18:38:06 2009
@@ -3384,7 +3384,9 @@
   // lexical context will be different from the semantic context.
   New->setLexicalDeclContext(CurContext);
 
-  if (AS != AS_none)
+  if (PrevDecl)
+    New->setAccess(PrevDecl->getAccess());
+  else
     New->setAccess(AS);
 
   if (TK == TK_Definition)

Modified: cfe/trunk/test/SemaCXX/nested-name-spec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nested-name-spec.cpp?rev=67717&r1=67716&r2=67717&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/nested-name-spec.cpp (original)
+++ cfe/trunk/test/SemaCXX/nested-name-spec.cpp Wed Mar 25 18:38:06 2009
@@ -170,4 +170,3 @@
 X::X() : a(5) { } // expected-error{{use of undeclared identifier 'X'}} \
       // expected-error{{C++ requires a type specifier for all declarations}} \
       // expected-error{{only constructors take base initializers}}
-





More information about the cfe-commits mailing list