[cfe-commits] r68991 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/Sema/incomplete-decl.c

Eli Friedman eli.friedman at gmail.com
Mon Apr 13 14:28:54 PDT 2009


Author: efriedma
Date: Mon Apr 13 16:28:54 2009
New Revision: 68991

URL: http://llvm.org/viewvc/llvm-project?rev=68991&view=rev
Log:
PR3461: reject initializer for incomplete type.  Based on patch by Tim
Northover.


Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/incomplete-decl.c

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=68991&r1=68990&r2=68991&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Apr 13 16:28:54 2009
@@ -2396,6 +2396,13 @@
     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) 

Modified: cfe/trunk/test/Sema/incomplete-decl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/incomplete-decl.c?rev=68991&r1=68990&r2=68991&view=diff

==============================================================================
--- cfe/trunk/test/Sema/incomplete-decl.c (original)
+++ cfe/trunk/test/Sema/incomplete-decl.c Mon Apr 13 16:28:54 2009
@@ -23,3 +23,8 @@
 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; };
+





More information about the cfe-commits mailing list