Revert "C++ doesn't really use "namespaces" for different kinds of names the same", which seems to break most C++ nightly test apps.

llvm-svn: 102174
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 445d08e..8de0c40 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -202,6 +202,26 @@
     !D->getDeclContext()->isRecord();
 }
 
+static bool IsAcceptableNestedNameSpecifierName(NamedDecl *D, unsigned IDNS) {
+  // This lookup ignores everything that isn't a type.
+
+  // This is a fast check for the far most common case.
+  if (D->isInIdentifierNamespace(Decl::IDNS_Tag))
+    return true;
+
+  if (isa<UsingShadowDecl>(D))
+    D = cast<UsingShadowDecl>(D)->getTargetDecl();
+
+  return isa<TypeDecl>(D);
+}
+
+static bool IsAcceptableNamespaceName(NamedDecl *D, unsigned IDNS) {
+  // We don't need to look through using decls here because
+  // using decls aren't allowed to name namespaces.
+
+  return isa<NamespaceDecl>(D) || isa<NamespaceAliasDecl>(D);
+}
+
 /// Gets the default result filter for the given lookup.
 static inline
 LookupResult::ResultFilter getResultFilter(Sema::LookupNameKind NameKind) {
@@ -212,12 +232,16 @@
   case Sema::LookupRedeclarationWithLinkage: // FIXME: check linkage, scoping
   case Sema::LookupUsingDeclName:
   case Sema::LookupObjCProtocolName:
-  case Sema::LookupNestedNameSpecifierName:
-  case Sema::LookupNamespaceName:
     return &IsAcceptableIDNS;
 
   case Sema::LookupOperatorName:
     return &IsAcceptableOperatorName;
+
+  case Sema::LookupNestedNameSpecifierName:
+    return &IsAcceptableNestedNameSpecifierName;
+
+  case Sema::LookupNamespaceName:
+    return &IsAcceptableNamespaceName;
   }
 
   llvm_unreachable("unkknown lookup kind");
@@ -236,25 +260,15 @@
   case Sema::LookupRedeclarationWithLinkage:
     IDNS = Decl::IDNS_Ordinary;
     if (CPlusPlus) {
-      IDNS |= Decl::IDNS_Tag | Decl::IDNS_Member | Decl::IDNS_Namespace;
+      IDNS |= Decl::IDNS_Tag | Decl::IDNS_Member;
       if (Redeclaration) IDNS |= Decl::IDNS_TagFriend | Decl::IDNS_OrdinaryFriend;
     }
     break;
 
   case Sema::LookupTagName:
-    if (CPlusPlus) {
-      IDNS = Decl::IDNS_Type;
-
-      // When looking for a redeclaration of a tag name, we add:
-      // 1) TagFriend to find undeclared friend decls
-      // 2) Namespace because they can't "overload" with tag decls.
-      // 3) Tag because it includes class templates, which can't
-      //    "overload" with tag decls.
-      if (Redeclaration)
-        IDNS |= Decl::IDNS_Tag | Decl::IDNS_TagFriend | Decl::IDNS_Namespace;
-    } else {
-      IDNS = Decl::IDNS_Tag;
-    }
+    IDNS = Decl::IDNS_Tag;
+    if (CPlusPlus && Redeclaration)
+      IDNS |= Decl::IDNS_TagFriend;
     break;
 
   case Sema::LookupMemberName:
@@ -264,11 +278,8 @@
     break;
 
   case Sema::LookupNestedNameSpecifierName:
-    IDNS = Decl::IDNS_Type | Decl::IDNS_Namespace;
-    break;
-
   case Sema::LookupNamespaceName:
-    IDNS = Decl::IDNS_Namespace;
+    IDNS = Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Member;
     break;
 
   case Sema::LookupUsingDeclName:
@@ -2123,8 +2134,7 @@
                                IEnd = Pos->second.end();
          I != IEnd; ++I) {
       // A tag declaration does not hide a non-tag declaration.
-      if ((*I)->getIdentifierNamespace()
-            == (Decl::IDNS_Tag|Decl::IDNS_Type) &&
+      if ((*I)->getIdentifierNamespace() == Decl::IDNS_Tag &&
           (IDNS & (Decl::IDNS_Member | Decl::IDNS_Ordinary | 
                    Decl::IDNS_ObjCProtocol)))
         continue;