r252967 - Avoid duplicated diagnostic when lookup for a nested-name-specifier fails due to ambiguity.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 12 14:40:09 PST 2015


Author: rsmith
Date: Thu Nov 12 16:40:09 2015
New Revision: 252967

URL: http://llvm.org/viewvc/llvm-project?rev=252967&view=rev
Log:
Avoid duplicated diagnostic when lookup for a nested-name-specifier fails due to ambiguity.

Modified:
    cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
    cfe/trunk/test/CXX/temp/temp.res/temp.local/p3.cpp
    cfe/trunk/test/Modules/no-linkage.cpp

Modified: cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp?rev=252967&r1=252966&r2=252967&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp Thu Nov 12 16:40:09 2015
@@ -533,6 +533,9 @@ bool Sema::BuildCXXNestedNameSpecifier(S
     LookupName(Found, S);
   }
 
+  if (Found.isAmbiguous())
+    return true;
+
   // If we performed lookup into a dependent context and did not find anything,
   // that's fine: just build a dependent nested-name-specifier.
   if (Found.empty() && isDependent &&
@@ -551,8 +554,6 @@ bool Sema::BuildCXXNestedNameSpecifier(S
     return false;
   }
 
-  // FIXME: Deal with ambiguities cleanly.
-
   if (Found.empty() && !ErrorRecoveryLookup) {
     // If identifier is not found as class-name-or-namespace-name, but is found
     // as other entity, don't look for typos.
@@ -562,6 +563,8 @@ bool Sema::BuildCXXNestedNameSpecifier(S
     else if (S && !isDependent)
       LookupName(R, S);
     if (!R.empty()) {
+      // Don't diagnose problems with this speculative lookup.
+      R.suppressDiagnostics();
       // The identifier is found in ordinary lookup. If correction to colon is
       // allowed, suggest replacement to ':'.
       if (IsCorrectedToColon) {

Modified: cfe/trunk/test/CXX/temp/temp.res/temp.local/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.res/temp.local/p3.cpp?rev=252967&r1=252966&r2=252967&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.res/temp.local/p3.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.res/temp.local/p3.cpp Thu Nov 12 16:40:09 2015
@@ -14,8 +14,7 @@ template <class T> struct Derived: Base<
     t->Derived::Base<T>::f();
     t->Base<T>::f();
     t->Base::f(); // expected-error{{member 'Base' found in multiple base classes of different types}} \
-    // expected-error{{no member named 'f' in 'X0'}} \
-    // expected-error{{'Base' is not a class, namespace, or enumeration}}
+    // expected-error{{no member named 'f' in 'X0'}}
   }
 };
 

Modified: cfe/trunk/test/Modules/no-linkage.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/no-linkage.cpp?rev=252967&r1=252966&r2=252967&view=diff
==============================================================================
--- cfe/trunk/test/Modules/no-linkage.cpp (original)
+++ cfe/trunk/test/Modules/no-linkage.cpp Thu Nov 12 16:40:09 2015
@@ -28,7 +28,7 @@ void use_things() {
 
 void use_things_again() {
   use(Typedef().n); // expected-error {{ambiguous}}
-  use(NS::n); // expected-error {{ambiguous}} expected-error{{'NS' is not a class, namespace, or enumeration}}
+  use(NS::n); // expected-error {{ambiguous}}
   use(AliasDecl); // expected-error {{ambiguous}}
   use(Enumerator); // expected-error {{ambiguous}}
   use(UsingDecl); // expected-error {{ambiguous}}




More information about the cfe-commits mailing list