PR3461: reject initializer for incomplete type. Based on patch by Tim

Northover.

llvm-svn: 68991
This commit is contained in:
Eli Friedman 2009-04-13 21:28:54 +00:00
parent c0a4ea0c02
commit 337cd3a536
2 changed files with 12 additions and 0 deletions

View File

@ -2396,6 +2396,13 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) {
return;
}
if (!VDecl->getType()->isArrayType() &&
RequireCompleteType(VDecl->getLocation(), VDecl->getType(),
diag::err_typecheck_decl_incomplete_type)) {
RealDecl->setInvalidDecl();
return;
}
const VarDecl *Def = 0;
if (VDecl->getDefinition(Def)) {
Diag(VDecl->getLocation(), diag::err_redefinition)

View File

@ -23,3 +23,8 @@ void func() {
int h[];
int (*i)[] = &h+1; // expected-error {{arithmetic on pointer to incomplete type 'int (*)[]'}}
struct bar j = {1}; // expected-error {{variable has incomplete type 'struct bar'}} \
expected-note {{forward declaration of 'struct bar'}}
struct bar k;
struct bar { int a; };