]> granicus.if.org Git - clang/commitdiff
There is no reason for dereferencing a pointer-to-member to require
authorDouglas Gregor <dgregor@apple.com>
Wed, 13 Oct 2010 20:41:14 +0000 (20:41 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 13 Oct 2010 20:41:14 +0000 (20:41 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116429 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprCXX.cpp
test/SemaCXX/member-pointer.cpp
test/SemaTemplate/instantiate-complete.cpp

index 00a3e27edc94e5e9eb165c8024343769ad9b3c16..38634794767f5f50efb33a3c6f07b670e0268b99 100644 (file)
@@ -2279,8 +2279,11 @@ QualType Sema::CheckPointerToMemberOperands(
 
   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
index 795c0b95efd6d9714f3a39b2d3537f49134e1e46..31c651a4ad5d6e527a5ed4d8298b6e3577225b68 100644 (file)
@@ -88,7 +88,7 @@ void g() {
   void (HasMembers::*pmd)() = &HasMembers::d;
 }
 
-struct Incomplete; // expected-note {{forward declaration}}
+struct Incomplete;
 
 void h() {
   HasMembers hm, *phm = &hm;
@@ -121,9 +121,10 @@ void h() {
   (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
index c13930d108c4409743d4153c17d7d4b03e740f3b..91d4d327073ed4e1136c42945de59f757467ee77 100644 (file)
@@ -11,8 +11,7 @@ struct X {
        // 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 @@ void test_memptr(X<long> *p1, long X<long>::*pm1,
                  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