From 2677e1073204747b10d231c441384750e1c08e09 Mon Sep 17 00:00:00 2001 From: John McCall Date: Mon, 16 Aug 2010 23:42:35 +0000 Subject: A field of incomplete type is sufficiently disruptive that we should mark the record invalid. llvm-svn: 111211 --- clang/lib/Sema/SemaDecl.cpp | 5 ++++- clang/test/SemaCXX/copy-assignment.cpp | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'clang') diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index cc6e2fa3501..b7b802a72f1 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -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. diff --git a/clang/test/SemaCXX/copy-assignment.cpp b/clang/test/SemaCXX/copy-assignment.cpp index bfe1501df86..5730b2af8f3 100644 --- a/clang/test/SemaCXX/copy-assignment.cpp +++ b/clang/test/SemaCXX/copy-assignment.cpp @@ -97,3 +97,15 @@ void test() { i = a; // expected-error{{assigning to 'int' from incompatible type 'A'}} } +// : Don't crash +// FIXME: the recovery here is really bad. +namespace test1 { + template 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 class B : public A { + virtual void foo() {} + }; + extern template class A; // expected-note {{in instantiation}} expected-note {{not complete}} + extern template class B; +} -- cgit v1.2.1