When a member pointer is dereferenced, the class it points into must be complete. Enforce this.

llvm-svn: 100925
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b29d071..7f99cff 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2140,6 +2140,8 @@
 def err_early_catch_all : Error<"catch-all handler must come last">;
 def err_bad_memptr_rhs : Error<
   "right hand operand to %0 has non pointer-to-member type %1">;
+def err_memptr_rhs_to_incomplete : Error<
+  "cannot dereference pointer into incomplete class type %0">;
 def err_bad_memptr_lhs : Error<
   "left hand operand to %0 must be a %select{|pointer to }1class "
   "compatible with the right hand operand, but is %2">;
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 7efba3a..04b3d83 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1847,6 +1847,9 @@
 
   QualType Class(MemPtr->getClass(), 0);
 
+  if (RequireCompleteType(Loc, Class, diag::err_memptr_rhs_to_incomplete))
+    return QualType();
+
   // C++ 5.5p2
   //   [...] to its first operand, which shall be of class T or of a class of
   //   which T is an unambiguous and accessible base class. [p3: a pointer to
diff --git a/clang/test/SemaCXX/member-pointer.cpp b/clang/test/SemaCXX/member-pointer.cpp
index ebdc921..aa941a1 100644
--- a/clang/test/SemaCXX/member-pointer.cpp
+++ b/clang/test/SemaCXX/member-pointer.cpp
@@ -88,7 +88,7 @@
   void (HasMembers::*pmd)() = &HasMembers::d;
 }
 
-struct Incomplete;
+struct Incomplete; // expected-note {{forward declaration}}
 
 void h() {
   HasMembers hm, *phm = &hm;
@@ -123,7 +123,7 @@
 
   Incomplete *inc;
   int Incomplete::*pii = 0;
-  (void)(inc->*pii); // okay
+  (void)(inc->*pii); // expected-error {{pointer into incomplete}}
 }
 
 struct OverloadsPtrMem
diff --git a/clang/test/SemaTemplate/instantiate-complete.cpp b/clang/test/SemaTemplate/instantiate-complete.cpp
index 82cc320..bc91112 100644
--- a/clang/test/SemaTemplate/instantiate-complete.cpp
+++ b/clang/test/SemaTemplate/instantiate-complete.cpp
@@ -11,7 +11,8 @@
        // 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 'float (float)'}} \
+       // expected-error{{data member instantiated with function type 'long (long)'}}
 };
 
 X<int> f() { return 0; }
@@ -43,7 +44,7 @@
                  X<long(long)> *p2, 
                  long (X<long(long)>::*pm2)(long)) {
   (void)(p1->*pm1);
-  (void)((p2->*pm2)(0));
+  (void)((p2->*pm2)(0)); // expected-note{{in instantiation of template class 'X<long (long)>' requested here}}
 }
 
 // Reference binding to a base