From caef2448daacb1eb16ac70aca78224d85a109e2c Mon Sep 17 00:00:00 2001
From: John McCall <rjmccall@apple.com>
Date: Wed, 11 Nov 2009 00:21:18 +0000
Subject: [PATCH] Create a new Scope when parsing a declaration with a C++
 scope specifier.

llvm-svn: 86764
---
 clang/include/clang/Parse/Parser.h                  |  9 ++++++++-
 clang/lib/Sema/SemaLookup.cpp                       |  3 ---
 .../dcl.dcl/basic.namespace/namespace.udir/p1.cpp   | 13 +++++++++++++
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index b163c81e18c5..dd939a98bf74 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -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();
     }
   };
 
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 31e64a9f8b45..13a66aaca01e 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -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);
diff --git a/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udir/p1.cpp b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udir/p1.cpp
index 5b8aadf3913d..fbd205833cad 100644
--- a/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udir/p1.cpp
+++ b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.udir/p1.cpp
@@ -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;
+}