]> granicus.if.org Git - clang/commitdiff
Create a new Scope when parsing a declaration with a C++ scope specifier.
authorJohn McCall <rjmccall@apple.com>
Wed, 11 Nov 2009 00:21:18 +0000 (00:21 +0000)
committerJohn McCall <rjmccall@apple.com>
Wed, 11 Nov 2009 00:21:18 +0000 (00:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86764 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Parse/Parser.h
lib/Sema/SemaLookup.cpp
test/CXX/dcl.dcl/basic.namespace/namespace.udir/p1.cpp

index b163c81e18c53745314b838b8cac12c3980cc6de..dd939a98bf740034944d6a6918ce76c0a7adcc87 100644 (file)
@@ -1226,13 +1226,18 @@ private:
     Parser &P;
     CXXScopeSpec &SS;
     bool EnteredScope;
+    bool CreatedScope;
   public:
     DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss)
-      : P(p), SS(ss), EnteredScope(false) {}
+      : P(p), SS(ss), EnteredScope(false), CreatedScope(false) {}
 
     void EnterDeclaratorScope() {
       assert(!EnteredScope && "Already entered the scope!");
       assert(SS.isSet() && "C++ scope was not set!");
+
+      CreatedScope = true;
+      P.EnterScope(0); // Not a decl scope.
+
       if (P.Actions.ActOnCXXEnterDeclaratorScope(P.CurScope, SS))
         SS.setScopeRep(0);
       
@@ -1245,6 +1250,8 @@ private:
         assert(SS.isSet() && "C++ scope was cleared ?");
         P.Actions.ActOnCXXExitDeclaratorScope(P.CurScope, SS);
       }
+      if (CreatedScope)
+        P.ExitScope();
     }
   };
 
index 31e64a9f8b45e10feaa216067c8b42d1acf7afb1..13a66aaca01ec56143c7404058edcd841c1ec185 100644 (file)
@@ -90,9 +90,6 @@ namespace {
       assert(InnermostFileDC && InnermostFileDC->isFileContext());
 
       for (; S; S = S->getParent()) {
-        if (!(S->getFlags() & Scope::DeclScope))
-          continue;
-
         if (DeclContext *Ctx = static_cast<DeclContext*>(S->getEntity())) {
           DeclContext *EffectiveDC = (Ctx->isFileContext() ? Ctx : InnermostFileDC);
           visit(Ctx, EffectiveDC);
index 5b8aadf3913d9efed6928f4444f77237dbfa9a82..fbd205833cad74e20549f9501cce83ba1070d1e8 100644 (file)
@@ -126,3 +126,16 @@ namespace test4 {
     return foo(); // expected-error {{call to 'foo' is ambiguous}}
   }
 }
+
+// Bug: using directives should be followed when parsing default
+// arguments in scoped declarations.
+class test5 {
+  int inc(int x);
+};
+namespace Test5 {
+  int default_x = 0;
+}
+using namespace Test5;
+int test5::inc(int x = default_x) {
+  return x+1;
+}