[cfe-commits] r46179 - in /cfe/trunk: Sema/SemaDecl.cpp test/Sema/array-constraint.c test/Sema/incomplete-decl.c

Steve Naroff snaroff at apple.com
Fri Jan 18 12:40:55 PST 2008


Author: snaroff
Date: Fri Jan 18 14:40:52 2008
New Revision: 46179

URL: http://llvm.org/viewvc/llvm-project?rev=46179&view=rev
Log:

Sema::FinalizeDeclaratorGroup(): Tighten up the tentative definition rule when dealing with arrays.

Bug submitted by Eli.

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

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

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Fri Jan 18 14:40:52 2008
@@ -855,10 +855,15 @@
     // 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();

Modified: cfe/trunk/test/Sema/array-constraint.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/array-constraint.c?rev=46179&r1=46178&r2=46179&view=diff

==============================================================================
--- cfe/trunk/test/Sema/array-constraint.c (original)
+++ cfe/trunk/test/Sema/array-constraint.c Fri Jan 18 14:40:52 2008
@@ -24,7 +24,7 @@
   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);

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

==============================================================================
--- cfe/trunk/test/Sema/incomplete-decl.c (original)
+++ cfe/trunk/test/Sema/incomplete-decl.c Fri Jan 18 14:40:52 2008
@@ -9,7 +9,11 @@
 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'}}
 }





More information about the cfe-commits mailing list