[cfe-commits] r129493 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/CXX/class/class.mfct/class.mfct.non-static/p3.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Wed Apr 13 17:46:47 PDT 2011


Author: akirtzidis
Date: Wed Apr 13 19:46:47 2011
New Revision: 129493

URL: http://llvm.org/viewvc/llvm-project?rev=129493&view=rev
Log:
When creating an implicit member expression through a qualified-id, check that the class
named by the nested-name-specifier is same or base of the class in which the member expression appears.

It seems we also had an ill-formed test case, mon dieu! Fixes rdar://8576107.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/CXX/class/class.mfct/class.mfct.non-static/p3.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=129493&r1=129492&r2=129493&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Apr 13 19:46:47 2011
@@ -1318,12 +1318,24 @@
     return IMA_Error_StaticContext;
   }
 
+  CXXRecordDecl *
+        contextClass = cast<CXXMethodDecl>(DC)->getParent()->getCanonicalDecl();
+
+  // [class.mfct.non-static]p3: 
+  // ...is used in the body of a non-static member function of class X,
+  // if name lookup (3.4.1) resolves the name in the id-expression to a
+  // non-static non-type member of some class C [...]
+  // ...if C is not X or a base class of X, the class member access expression
+  // is ill-formed.
+  if (R.getNamingClass() &&
+      contextClass != R.getNamingClass()->getCanonicalDecl() &&
+      contextClass->isProvablyNotDerivedFrom(R.getNamingClass()))
+    return (hasNonInstance ? IMA_Mixed_Unrelated : IMA_Error_Unrelated);
+
   // If we can prove that the current context is unrelated to all the
   // declaring classes, it can't be an implicit member reference (in
   // which case it's an error if any of those members are selected).
-  if (IsProvablyNotDerivedFrom(SemaRef,
-                               cast<CXXMethodDecl>(DC)->getParent(),
-                               Classes))
+  if (IsProvablyNotDerivedFrom(SemaRef, contextClass, Classes))
     return (hasNonInstance ? IMA_Mixed_Unrelated : IMA_Error_Unrelated);
 
   return (hasNonInstance ? IMA_Mixed : IMA_Instance);

Modified: cfe/trunk/test/CXX/class/class.mfct/class.mfct.non-static/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class/class.mfct/class.mfct.non-static/p3.cpp?rev=129493&r1=129492&r2=129493&view=diff
==============================================================================
--- cfe/trunk/test/CXX/class/class.mfct/class.mfct.non-static/p3.cpp (original)
+++ cfe/trunk/test/CXX/class/class.mfct/class.mfct.non-static/p3.cpp Wed Apr 13 19:46:47 2011
@@ -35,17 +35,22 @@
   struct A {
     void foo(Opaque1); // expected-note {{candidate}}
     void foo(Opaque2); // expected-note {{candidate}}
-    void test();
   };
 
   struct B : A {
-    
+    void test();
   };
 
-  void A::test() {
-    B::foo(Opaque1());
-    B::foo(Opaque2());
-    B::foo(Opaque3()); // expected-error {{no matching member function}}
+  struct C1 : A { };
+  struct C2 : B { };
+
+  void B::test() {
+    A::foo(Opaque1());
+    A::foo(Opaque2());
+    A::foo(Opaque3()); // expected-error {{no matching member function}}
+
+    C1::foo(Opaque1()); // expected-error {{call to non-static member function without an object argument}}
+    C2::foo(Opaque1()); // expected-error {{call to non-static member function without an object argument}}
   }
 }
 





More information about the cfe-commits mailing list