]> granicus.if.org Git - clang/commitdiff
Sema::FinalizeDeclaratorGroup(): Tighten up the tentative definition rule when dealin...
authorSteve Naroff <snaroff@apple.com>
Fri, 18 Jan 2008 20:40:52 +0000 (20:40 +0000)
committerSteve Naroff <snaroff@apple.com>
Fri, 18 Jan 2008 20:40:52 +0000 (20:40 +0000)
Bug submitted by Eli.

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

Sema/SemaDecl.cpp
test/Sema/array-constraint.c
test/Sema/incomplete-decl.c

index c2c66a20152a0df24b900e54c85c054be047d29b..b1753e1df418f20b43454bf93151ab6e0083896e 100644 (file)
@@ -855,10 +855,15 @@ Sema::DeclTy *Sema::FinalizeDeclaratorGroup(Scope *S, DeclTy *group) {
     // external linkage is valid (C99 6.2.2p5).
     if (FVD && !FVD->getInit() && (FVD->getStorageClass() == VarDecl::Static || 
                                    FVD->getStorageClass() == VarDecl::None)) {
-      // C99 6.9.2p3: If the declaration of an identifier for an object is
-      // a tentative definition and has internal linkage (C99 6.2.2p3), the  
-      // declared type shall not be an incomplete type.
-      if (T->isIncompleteType()) {
+      const VariableArrayType *VAT = T->getAsVariableArrayType();
+      
+      if (VAT && VAT->getSizeExpr() == 0) {
+        // C99 6.9.2 (p2, p5): Implicit initialization causes an incomplete
+        // array to be completed. Don't issue a diagnostic.
+      } else if (T->isIncompleteType()) {
+        // C99 6.9.2p3: If the declaration of an identifier for an object is
+        // a tentative definition and has internal linkage (C99 6.2.2p3), the  
+        // declared type shall not be an incomplete type.
         Diag(IDecl->getLocation(), diag::err_typecheck_decl_incomplete_type,
              T.getAsString());
         IDecl->setInvalidDecl();
index 8b2ce5eca4cb166e4f663755777c6c18b98f2279..3ed5215accb1621cc71123b100e06339be490d04 100644 (file)
@@ -24,7 +24,7 @@ struct vari *func(struct vari a[]) { // expected-error {{'struct vari' may not b
   return a;
 }
 
-int foo[](void);  // expected-error {{variable has incomplete type 'int (*[])(void)'}} expected-error {{'foo' declared as array of functions}}
+int foo[](void);  // expected-error {{'foo' declared as array of functions}}
 int foo2[1](void);  // expected-error {{'foo2' declared as array of functions}}
 
 typedef int (*pfunc)(void);
index e342ab8b70cb6c0a8aacd24147ff5ed0913870f6..047c24266e38647811d8f0788914e6ff2d51860d 100644 (file)
@@ -9,7 +9,11 @@ static struct foo g;  // expected-error {{variable has incomplete type 'struct f
 extern void d;
 extern struct foo e;
 
+int ary[];
+struct foo bary[]; // expected-error {{array has incomplete element type 'struct foo'}}
+
 void func() {
+  int ary[]; // expected-error{{variable has incomplete type 'int []'}}
   void b; // expected-error {{variable has incomplete type 'void'}}
   struct foo f; // expected-error {{variable has incomplete type 'struct foo'}}
 }