[cfe-commits] r170976 - in /cfe/trunk: lib/Sema/SemaOverload.cpp test/SemaTemplate/dependent-names.cpp

Richard Smith richard-llvm at metafoo.co.uk
Fri Dec 21 18:46:14 PST 2012


Author: rsmith
Date: Fri Dec 21 20:46:14 2012
New Revision: 170976

URL: http://llvm.org/viewvc/llvm-project?rev=170976&view=rev
Log:
PR14695: Fix assert from bad cast<>. Not every namespace is a NamespaceDecl; it might instead be a TranslationUnitDecl.

Modified:
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/test/SemaTemplate/dependent-names.cpp

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=170976&r1=170975&r2=170976&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri Dec 21 20:46:14 2012
@@ -9541,16 +9541,23 @@
       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)

Modified: cfe/trunk/test/SemaTemplate/dependent-names.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/dependent-names.cpp?rev=170976&r1=170975&r2=170976&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/dependent-names.cpp (original)
+++ cfe/trunk/test/SemaTemplate/dependent-names.cpp Fri Dec 21 20:46:14 2012
@@ -360,3 +360,12 @@
     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}}





More information about the cfe-commits mailing list