[cfe-commits] r102409 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaExpr.cpp test/SemaCXX/qual-id-test.cpp test/SemaTemplate/instantiate-member-expr.cpp

John McCall rjmccall at apple.com
Mon Apr 26 18:43:38 PDT 2010


Author: rjmccall
Date: Mon Apr 26 20:43:38 2010
New Revision: 102409

URL: http://llvm.org/viewvc/llvm-project?rev=102409&view=rev
Log:
Improve the diagnostic you get when making a qualified member access
with a qualifier referencing a different type.


Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/qual-id-test.cpp
    cfe/trunk/test/SemaTemplate/instantiate-member-expr.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=102409&r1=102408&r2=102409&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Apr 26 20:43:38 2010
@@ -564,6 +564,8 @@
 def err_implicit_object_parameter_init : Error<
   "cannot initialize object parameter of type %0 with an expression "
   "of type %1">;
+def err_qualified_member_of_unrelated : Error<
+  "%q0 is not a member of class %1">;
 
 def note_field_decl : Note<"member is declared here">;
 def note_ivar_decl : Note<"ivar is declared here">;
@@ -2565,9 +2567,7 @@
   "base class initializer %0 names both a direct base class and an "
   "inherited virtual base class">;
 def err_not_direct_base_or_virtual : Error<
-  "type %0 is not a direct or virtual base of '%1'">;
-def err_not_direct_base_or_virtual_multi : Error<
-  "type %0 is not a direct or virtual base of '%1'">;
+  "type %0 is not a direct or virtual base of %1">;
 
 def err_in_class_initializer_non_integral_type : Error<
   "in-class initializer has non-integral, non-enumeration type %0">;

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=102409&r1=102408&r2=102409&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Apr 26 20:43:38 2010
@@ -1406,7 +1406,7 @@
   // mem-initializer is ill-formed.
   if (!DirectBaseSpec && !VirtualBaseSpec)
     return Diag(BaseLoc, diag::err_not_direct_base_or_virtual)
-      << BaseType << ClassDecl->getNameAsCString()
+      << BaseType << Context.getTypeDeclType(ClassDecl)
       << BaseTInfo->getTypeLoc().getSourceRange();
 
   CXXBaseSpecifier *BaseSpec

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=102409&r1=102408&r2=102409&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Apr 26 20:43:38 2010
@@ -2499,11 +2499,8 @@
   if (!BaseExpr)
     return DiagnoseInstanceReference(SemaRef, SS, R);
 
-  // FIXME: this is an exceedingly lame diagnostic for some of the more
-  // complicated cases here.
-  DeclContext *DC = R.getRepresentativeDecl()->getDeclContext();
-  SemaRef.Diag(R.getNameLoc(), diag::err_not_direct_base_or_virtual)
-    << SS.getRange() << DC << BaseType;
+  SemaRef.Diag(R.getNameLoc(), diag::err_qualified_member_of_unrelated)
+    << SS.getRange() << R.getRepresentativeDecl() << BaseType;
 }
 
 // Check whether the declarations we found through a nested-name

Modified: cfe/trunk/test/SemaCXX/qual-id-test.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/qual-id-test.cpp?rev=102409&r1=102408&r2=102409&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/qual-id-test.cpp (original)
+++ cfe/trunk/test/SemaCXX/qual-id-test.cpp Mon Apr 26 20:43:38 2010
@@ -48,7 +48,7 @@
         a.A::sub::x();
         a.A::B::base::x();
 
-        a.bad::x(); // expected-error{{type 'bad' is not a direct or virtual base of ''A::sub''}}
+        a.bad::x(); // expected-error{{'bad::x' is not a member of class 'A::sub'}}
 
         a->foo();
         a->member::foo();
@@ -69,7 +69,7 @@
         a->A::sub::x();
         a->A::B::base::x();
 
-        a->bad::x(); // expected-error{{type 'bad' is not a direct or virtual base of ''A::sub''}}
+        a->bad::x(); // expected-error{{'bad::x' is not a member of class 'A::sub'}}
 
         (*a)->foo();
         (*a)->member::foo();
@@ -107,7 +107,7 @@
         a.A::B::base::x();
         a->A::member::foo();
 
-        a.bad::x(); // expected-error{{direct or virtual}}
+        a.bad::x(); // expected-error{{'bad::x' is not a member of class 'A::sub'}}
     }
 
   void test_fun5() {

Modified: cfe/trunk/test/SemaTemplate/instantiate-member-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-member-expr.cpp?rev=102409&r1=102408&r2=102409&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-member-expr.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-member-expr.cpp Mon Apr 26 20:43:38 2010
@@ -43,7 +43,7 @@
     int a;
     template<typename T> struct B : A<T> {
       void f() {
-        a = 0; // expected-error {{type 'test1::O' is not a direct or virtual base of ''test1::O::B<int>''}}
+        a = 0; // expected-error {{'test1::O::a' is not a member of class 'test1::O::B<int>'}}
       }
     };
   };





More information about the cfe-commits mailing list