[cfe-commits] r116429 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/SemaCXX/member-pointer.cpp test/SemaTemplate/instantiate-complete.cpp

Douglas Gregor dgregor at apple.com
Wed Oct 13 13:41:14 PDT 2010


Author: dgregor
Date: Wed Oct 13 15:41:14 2010
New Revision: 116429

URL: http://llvm.org/viewvc/llvm-project?rev=116429&view=rev
Log:
There is no reason for dereferencing a pointer-to-member to require
that the class type into which the pointer points be complete, even
though the standard requires it. GCC/EDG do not require a complete
type here, so we're calling this a problem with the standard. Fixes
PR8328.

Modified:
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/SemaCXX/member-pointer.cpp
    cfe/trunk/test/SemaTemplate/instantiate-complete.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=116429&r1=116428&r2=116429&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Oct 13 15:41:14 2010
@@ -2279,8 +2279,11 @@
 
   QualType Class(MemPtr->getClass(), 0);
 
-  if (RequireCompleteType(Loc, Class, diag::err_memptr_rhs_to_incomplete))
-    return QualType();
+  // Note: C++ [expr.mptr.oper]p2-3 says that the class type into which the
+  // member pointer points must be completely-defined. However, there is no
+  // reason for this semantic distinction, and the rule is not enforced by
+  // other compilers. Therefore, we do not check this property, as it is
+  // likely to be considered a defect.
 
   // C++ 5.5p2
   //   [...] to its first operand, which shall be of class T or of a class of

Modified: cfe/trunk/test/SemaCXX/member-pointer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/member-pointer.cpp?rev=116429&r1=116428&r2=116429&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/member-pointer.cpp (original)
+++ cfe/trunk/test/SemaCXX/member-pointer.cpp Wed Oct 13 15:41:14 2010
@@ -88,7 +88,7 @@
   void (HasMembers::*pmd)() = &HasMembers::d;
 }
 
-struct Incomplete; // expected-note {{forward declaration}}
+struct Incomplete;
 
 void h() {
   HasMembers hm, *phm = &hm;
@@ -121,9 +121,10 @@
   (void)(hm.*i); // expected-error {{pointer-to-member}}
   (void)(phm->*i); // expected-error {{pointer-to-member}}
 
+  // Okay
   Incomplete *inc;
   int Incomplete::*pii = 0;
-  (void)(inc->*pii); // expected-error {{pointer into incomplete}}
+  (void)(inc->*pii);
 }
 
 struct OverloadsPtrMem

Modified: cfe/trunk/test/SemaTemplate/instantiate-complete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-complete.cpp?rev=116429&r1=116428&r2=116429&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-complete.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-complete.cpp Wed Oct 13 15:41:14 2010
@@ -11,8 +11,7 @@
        // expected-error{{data member instantiated with function type 'int (int)'}} \
        // expected-error{{data member instantiated with function type 'char (char)'}} \
        // expected-error{{data member instantiated with function type 'short (short)'}} \
-       // expected-error{{data member instantiated with function type 'float (float)'}} \
-       // expected-error{{data member instantiated with function type 'long (long)'}}
+       // expected-error{{data member instantiated with function type 'float (float)'}}
 };
 
 X<int> f() { return 0; }
@@ -44,7 +43,6 @@
                  X<long(long)> *p2, 
                  long (X<long(long)>::*pm2)(long)) {
   (void)(p1->*pm1);
-  (void)((p2->*pm2)(0)); // expected-note{{in instantiation of template class 'X<long (long)>' requested here}}
 }
 
 // Reference binding to a base





More information about the cfe-commits mailing list