From: Eli Friedman Date: Mon, 13 Apr 2009 21:28:54 +0000 (+0000) Subject: PR3461: reject initializer for incomplete type. Based on patch by Tim X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a31fecaf63dc589af70bc1604f6d2aabeb7769f7;p=clang PR3461: reject initializer for incomplete type. Based on patch by Tim Northover. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68991 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 018f74816a..ef8b9e842e 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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) diff --git a/test/Sema/incomplete-decl.c b/test/Sema/incomplete-decl.c index 8468cf47ab..c4183ca72f 100644 --- a/test/Sema/incomplete-decl.c +++ b/test/Sema/incomplete-decl.c @@ -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; }; +