From: Douglas Gregor Date: Wed, 13 Oct 2010 20:41:14 +0000 (+0000) Subject: There is no reason for dereferencing a pointer-to-member to require X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7d520baec9b762633a09d31ee0db12e41fe2758a;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116429 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 00a3e27edc..3863479476 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -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 diff --git a/test/SemaCXX/member-pointer.cpp b/test/SemaCXX/member-pointer.cpp index 795c0b95ef..31c651a4ad 100644 --- a/test/SemaCXX/member-pointer.cpp +++ b/test/SemaCXX/member-pointer.cpp @@ -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 diff --git a/test/SemaTemplate/instantiate-complete.cpp b/test/SemaTemplate/instantiate-complete.cpp index c13930d108..91d4d32707 100644 --- a/test/SemaTemplate/instantiate-complete.cpp +++ b/test/SemaTemplate/instantiate-complete.cpp @@ -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 f() { return 0; } @@ -44,7 +43,6 @@ void test_memptr(X *p1, long X::*pm1, X *p2, long (X::*pm2)(long)) { (void)(p1->*pm1); - (void)((p2->*pm2)(0)); // expected-note{{in instantiation of template class 'X' requested here}} } // Reference binding to a base