[cfe-commits] r111211 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaCXX/copy-assignment.cpp

John McCall rjmccall at apple.com
Mon Aug 16 16:42:35 PDT 2010


Author: rjmccall
Date: Mon Aug 16 18:42:35 2010
New Revision: 111211

URL: http://llvm.org/viewvc/llvm-project?rev=111211&view=rev
Log:
A field of incomplete type is sufficiently disruptive that we should mark
the record invalid.


Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/copy-assignment.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=111211&r1=111210&r2=111211&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Aug 16 18:42:35 2010
@@ -5955,8 +5955,11 @@
 
   QualType EltTy = Context.getBaseElementType(T);
   if (!EltTy->isDependentType() &&
-      RequireCompleteType(Loc, EltTy, diag::err_field_incomplete))
+      RequireCompleteType(Loc, EltTy, diag::err_field_incomplete)) {
+    // Fields of incomplete type force their record to be invalid.
+    Record->setInvalidDecl();
     InvalidDecl = true;
+  }
 
   // C99 6.7.2.1p8: A member of a structure or union may have any type other
   // than a variably modified type.

Modified: cfe/trunk/test/SemaCXX/copy-assignment.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/copy-assignment.cpp?rev=111211&r1=111210&r2=111211&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/copy-assignment.cpp (original)
+++ cfe/trunk/test/SemaCXX/copy-assignment.cpp Mon Aug 16 18:42:35 2010
@@ -97,3 +97,15 @@
   i = a; // expected-error{{assigning to 'int' from incompatible type 'A'}}
 }
 
+// <rdar://problem/8315440>: Don't crash
+// FIXME: the recovery here is really bad.
+namespace test1 {
+  template<typename T> class A : public unknown::X { // expected-error {{undeclared identifier 'unknown'}} expected-error {{expected class name}}
+    A(UndeclaredType n) : X(n) {} // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{undeclared identifier 'n'}} expected-error {{expected ';' at end}} expected-error {{field has incomplete type}}
+  };
+  template<typename T> class B : public A<T>     {
+    virtual void foo() {}
+  };
+  extern template class A<char>; // expected-note {{in instantiation}} expected-note {{not complete}}
+  extern template class B<char>;
+}





More information about the cfe-commits mailing list