]> granicus.if.org Git - clang/commitdiff
A field of incomplete type is sufficiently disruptive that we should mark
authorJohn McCall <rjmccall@apple.com>
Mon, 16 Aug 2010 23:42:35 +0000 (23:42 +0000)
committerJohn McCall <rjmccall@apple.com>
Mon, 16 Aug 2010 23:42:35 +0000 (23:42 +0000)
the record invalid.

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

lib/Sema/SemaDecl.cpp
test/SemaCXX/copy-assignment.cpp

index cc6e2fa35014848f48e4c0f1920959f216f5b9a1..b7b802a72f12e5b443dc18d1720d9ac723cb25b4 100644 (file)
@@ -5955,8 +5955,11 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T,
 
   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.
index bfe1501df86794432ec745f445cb63f446b8de4c..5730b2af8f3f0811d53726c5af14eba34c08ac6f 100644 (file)
@@ -97,3 +97,15 @@ void test() {
   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>;
+}