]> granicus.if.org Git - clang/commitdiff
PR14695: Fix assert from bad cast<>. Not every namespace is a NamespaceDecl; it might...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 22 Dec 2012 02:46:14 +0000 (02:46 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 22 Dec 2012 02:46:14 +0000 (02:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170976 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaOverload.cpp
test/SemaTemplate/dependent-names.cpp

index 2d82750e1b66ffc80fa03ad2c6fd0e6b4c43428b..e5af2b16d70db51744a4c7ab4439832f23070fe1 100644 (file)
@@ -9541,16 +9541,23 @@ DiagnoseTwoPhaseLookup(Sema &SemaRef, SourceLocation FnLoc,
       SemaRef.FindAssociatedClassesAndNamespaces(FnLoc, Args,
                                                  AssociatedNamespaces,
                                                  AssociatedClasses);
-      // Never suggest declaring a function within namespace 'std'.
       Sema::AssociatedNamespaceSet SuggestedNamespaces;
       DeclContext *Std = SemaRef.getStdNamespace();
       for (Sema::AssociatedNamespaceSet::iterator
              it = AssociatedNamespaces.begin(),
              end = AssociatedNamespaces.end(); it != end; ++it) {
-        NamespaceDecl *Assoc = cast<NamespaceDecl>(*it);
-        if ((!Std || !Std->Encloses(Assoc)) &&
-            Assoc->getQualifiedNameAsString().find("__") == std::string::npos)
-          SuggestedNamespaces.insert(Assoc);
+        // Never suggest declaring a function within namespace 'std'.
+        if (Std && Std->Encloses(*it))
+          continue;
+        
+        // Never suggest declaring a function within a namespace with a reserved
+        // name, like __gnu_cxx.
+        NamespaceDecl *NS = dyn_cast<NamespaceDecl>(*it);
+        if (NS &&
+            NS->getQualifiedNameAsString().find("__") != std::string::npos)
+          continue;
+
+        SuggestedNamespaces.insert(*it);
       }
 
       SemaRef.Diag(R.getNameLoc(), diag::err_not_found_by_two_phase_lookup)
index 7ef12b8788b7d53b77e85f5de2a84031e2e9230c..eb75e69ef4de2e63bfe748784f4301c0ca754dc6 100644 (file)
@@ -360,3 +360,12 @@ namespace test_reserved_identifiers {
     tempf(x, y);  // expected-note{{in instantiation of}}
   }
 }
+
+// This test must live in the global namespace.
+struct PR14695_X {};
+// FIXME: This note is bogus; it is the using directive which would need to move
+// to prior to the call site to fix the problem.
+namespace PR14695_A { void PR14695_f(PR14695_X); } // expected-note {{'PR14695_f' should be declared prior to the call site or in the global namespace}}
+template<typename T> void PR14695_g(T t) { PR14695_f(t); } // expected-error {{call to function 'PR14695_f' that is neither visible in the template definition nor found by argument-dependent lookup}}
+using namespace PR14695_A;
+template void PR14695_g(PR14695_X); // expected-note{{requested here}}