]> granicus.if.org Git - clang/commitdiff
Make name lookup when we're inside a declarator's scope, such as ClassName::func...
authorDouglas Gregor <dgregor@apple.com>
Tue, 16 Dec 2008 00:38:16 +0000 (00:38 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 16 Dec 2008 00:38:16 +0000 (00:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61060 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Parse/Action.h
include/clang/Parse/Parser.h
lib/Sema/Sema.h
lib/Sema/SemaCXXScopeSpec.cpp
lib/Sema/SemaDecl.cpp
test/SemaCXX/default2.cpp

index bfb32000d0450367db3eb98ea02166c735ab7b3a..af7255490822dfa26e5d46c844a4ba6d0e0c49e5 100644 (file)
@@ -152,7 +152,7 @@ public:
   /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
   /// Used to indicate that names should revert to being looked up in the
   /// defining scope.
-  virtual void ActOnCXXExitDeclaratorScope(const CXXScopeSpec &SS) {
+  virtual void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS) {
   }
 
   /// ActOnDeclarator - This callback is invoked when a declarator is parsed and
index d6a3efdd5ef5668b86fd650dbc3acef3ea039f41..ba5cc84b99c25fbcbcb0e0f9e1858996c0c1e581 100644 (file)
@@ -819,7 +819,7 @@ private:
 
     ~DeclaratorScopeObj() {
       if (SS.isSet())
-        P.Actions.ActOnCXXExitDeclaratorScope(SS);
+        P.Actions.ActOnCXXExitDeclaratorScope(P.CurScope, SS);
     }
   };
   
index bebd0cfe740acb81f6c7f0d9bfd7aa355b79bd45..6ce3ec5dd390804f23e755944b5031803647daff 100644 (file)
@@ -903,7 +903,7 @@ public:
   /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
   /// Used to indicate that names should revert to being looked up in the
   /// defining scope.
-  virtual void ActOnCXXExitDeclaratorScope(const CXXScopeSpec &SS);
+  virtual void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
 
   // ParseObjCStringLiteral - Parse Objective-C string literals.
   virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, 
index 193e259f1da41a73e0aa498fcd3cf2ecdc64928b..8b3218b33b194de9b9bdc82df28243d9e08c8847 100644 (file)
@@ -134,8 +134,8 @@ Sema::CXXScopeTy *Sema::ActOnCXXNestedNameSpecifier(Scope *S,
 void Sema::ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS) {\r
   assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");\r
   assert(PreDeclaratorDC == 0 && "Previous declarator context not popped?");\r
-  PreDeclaratorDC = CurContext;\r
-  CurContext = static_cast<DeclContext*>(SS.getScopeRep());\r
+  PreDeclaratorDC = static_cast<DeclContext*>(S->getEntity());\r
+  S->setEntity(static_cast<DeclContext*>(SS.getScopeRep()));\r
 }\r
 \r
 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously\r
@@ -143,10 +143,9 @@ void Sema::ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS) {
 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.\r
 /// Used to indicate that names should revert to being looked up in the\r
 /// defining scope.\r
-void Sema::ActOnCXXExitDeclaratorScope(const CXXScopeSpec &SS) {\r
+void Sema::ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS) {\r
   assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");\r
-  assert(CurContext == static_cast<DeclContext*>(SS.getScopeRep()) &&\r
-         "Context imbalance!");\r
-  CurContext = PreDeclaratorDC;\r
+  assert(S->getEntity() == SS.getScopeRep() && "Context imbalance!");\r
+  S->setEntity(PreDeclaratorDC);\r
   PreDeclaratorDC = 0;\r
 }\r
index 1be30715e5c0ca4379934df76c217495d78d655a..5e0edcd1ecf55bed51f3885c5b1090ac05fbf887 100644 (file)
@@ -221,7 +221,7 @@ ObjCInterfaceDecl *Sema::getObjCInterfaceDecl(IdentifierInfo *Id) {
 Decl *Sema::LookupDecl(DeclarationName Name, unsigned NSI, Scope *S,
                        const DeclContext *LookupCtx,
                        bool enableLazyBuiltinCreation,
-                      bool LookInParent) {
+                       bool LookInParent) {
   if (!Name) return 0;
   unsigned NS = NSI;
   if (getLangOptions().CPlusPlus && (NS & Decl::IDNS_Ordinary))
index 6a8bcb121c1ee257ec3e916135e63e781ca18bb6..e5fe48d1cb754c878f78b92c10b6f502dc309e65 100644 (file)
@@ -68,5 +68,12 @@ class Y {
   int mem1(int i = a); // expected-error{{invalid use of nonstatic data member 'a'}}
   // FIXME: The code below is well-formed.
   //  int mem2(int i = b); // OK; use X::b 
+  int mem3(int i);
+  int mem4(int i);
   static int b; 
 }; 
+
+int Y::mem3(int i = b) { return i; } // OK; use X::b
+
+int Y::mem4(int i = a) // expected-error{{invalid use of nonstatic data member 'a'}}
+{ return i; }