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

Nick Lewycky nicholas at mxc.ca
Mon Nov 12 16:08:34 PST 2012


Author: nicholas
Date: Mon Nov 12 18:08:34 2012
New Revision: 167786

URL: http://llvm.org/viewvc/llvm-project?rev=167786&view=rev
Log:
When filtering the list of associated namespaces so that we don't suggest people
add functions to namespace 'std', also filter out namespaces with '__' anywhere
in the name.

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=167786&r1=167785&r2=167786&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Mon Nov 12 18:08:34 2012
@@ -9536,18 +9536,16 @@
       SemaRef.FindAssociatedClassesAndNamespaces(FnLoc, Args,
                                                  AssociatedNamespaces,
                                                  AssociatedClasses);
-      // Never suggest declaring a function within namespace 'std'. 
+      // Never suggest declaring a function within namespace 'std'.
       Sema::AssociatedNamespaceSet SuggestedNamespaces;
-      if (DeclContext *Std = SemaRef.getStdNamespace()) {
-        for (Sema::AssociatedNamespaceSet::iterator
-               it = AssociatedNamespaces.begin(),
-               end = AssociatedNamespaces.end(); it != end; ++it) {
-          if (!Std->Encloses(*it))
-            SuggestedNamespaces.insert(*it);
-        }
-      } else {
-        // Lacking the 'std::' namespace, use all of the associated namespaces.
-        SuggestedNamespaces = AssociatedNamespaces;
+      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);
       }
 
       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=167786&r1=167785&r2=167786&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/dependent-names.cpp (original)
+++ cfe/trunk/test/SemaTemplate/dependent-names.cpp Mon Nov 12 18:08:34 2012
@@ -346,3 +346,17 @@
     virtual void foo() { }
   };
 }
+
+namespace test_reserved_identifiers {
+  template<typename A, typename B> void tempf(A a, B b) {
+    a + b;  // expected-error{{call to function 'operator+' that is neither visible in the template definition nor found by argument-dependent lookup}}
+  }
+  namespace __gnu_cxx { struct X {}; }
+  namespace ns { struct Y {}; }
+  void operator+(__gnu_cxx::X, ns::Y);  // expected-note{{or in namespace 'test_reserved_identifiers::ns'}}
+  void test() {
+    __gnu_cxx::X x;
+    ns::Y y;
+    tempf(x, y);  // expected-note{{in instantiation of}}
+  }
+}





More information about the cfe-commits mailing list