[cfe-commits] r63987 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.def lib/Sema/SemaExpr.cpp test/SemaCXX/member-pointer.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Fri Feb 6 16:41:42 PST 2009


Author: cornedbee
Date: Fri Feb  6 18:41:42 2009
New Revision: 63987

URL: http://llvm.org/viewvc/llvm-project?rev=63987&view=rev
Log:
Add negative test cases and fix diagnostics for member pointer dereferencing.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/member-pointer.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def?rev=63987&r1=63986&r2=63987&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def Fri Feb  6 18:41:42 2009
@@ -867,8 +867,8 @@
      "right hand operand to %0 must be a pointer to member of a complete class "
      "but is %1")
 DIAG(err_bad_memptr_lhs, ERROR,
-     "left hand operand to ->* must be a %select{|pointer to }0class "
-     "compatible with the right hand operand, but is %1")
+     "left hand operand to %0 must be a %select{|pointer to }1class "
+     "compatible with the right hand operand, but is %2")
 
 DIAG(err_invalid_use_of_function_type, ERROR,
      "a function type is not allowed here")

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=63987&r1=63986&r2=63987&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Feb  6 18:41:42 2009
@@ -2731,7 +2731,7 @@
       LType = Ptr->getPointeeType().getNonReferenceType();
     else {
       Diag(Loc, diag::err_bad_memptr_lhs)
-        << 1 << LType << lex->getSourceRange();
+        << OpSpelling << 1 << LType << lex->getSourceRange();
       return QualType();
     }
   }
@@ -2744,7 +2744,7 @@
     // or is that overkill?
     if (!IsDerivedFrom(LType, Class, Paths) ||
         Paths.isAmbiguous(Context.getCanonicalType(Class))) {
-      Diag(Loc, diag::err_bad_memptr_lhs)
+      Diag(Loc, diag::err_bad_memptr_lhs) << OpSpelling
         << (int)isIndirect << lex->getType() << lex->getSourceRange();
       return QualType();
     }

Modified: cfe/trunk/test/SemaCXX/member-pointer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/member-pointer.cpp?rev=63987&r1=63986&r2=63987&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/member-pointer.cpp (original)
+++ cfe/trunk/test/SemaCXX/member-pointer.cpp Fri Feb  6 18:41:42 2009
@@ -80,6 +80,8 @@
   void (HasMembers::*pmd)() = &HasMembers::d;
 }
 
+struct Incomplete;
+
 void h() {
   HasMembers hm, *phm = &hm;
 
@@ -93,6 +95,27 @@
   void (HasMembers::*pf)() = &HasMembers::f;
   (hm.*pf)();
   (phm->*pf)();
+
+  (void)(hm->*pi); // expected-error {{left hand operand to ->* must be a pointer to class compatible with the right hand operand, but is 'struct HasMembers'}}
+  (void)(phm.*pi); // expected-error {{left hand operand to .* must be a class compatible with the right hand operand, but is 'struct HasMembers *'}}
+  (void)(i.*pi); // expected-error {{left hand operand to .* must be a class compatible with the right hand operand, but is 'int'}}
+  int *ptr;
+  (void)(ptr->*pi); // expected-error {{left hand operand to ->* must be a pointer to class compatible with the right hand operand, but is 'int *'}}
+
+  int A::*pai = 0;
+  D d, *pd = &d;
+  (void)(d.*pai);
+  (void)(pd->*pai);
+  F f, *ptrf = &f;
+  (void)(f.*pai); // expected-error {{left hand operand to .* must be a class compatible with the right hand operand, but is 'struct F'}}
+  (void)(ptrf->*pai); // expected-error {{left hand operand to ->* must be a pointer to class compatible with the right hand operand, but is 'struct F *'}}
+
+  (void)(hm.*i); // expected-error {{right hand operand to .* must be a pointer to member of a complete class but is 'int'}}
+  (void)(phm->*i); // expected-error {{right hand operand to ->* must be a pointer to member of a complete class but is 'int'}}
+
+  Incomplete *inc;
+  int Incomplete::*pii = 0;
+  (void)inc->*pii; // expected-error {{right hand operand to ->* must be a pointer to member of a complete class but is 'int struct Incomplete::*'}}
 }
 
 struct OverloadsPtrMem





More information about the cfe-commits mailing list