]> granicus.if.org Git - clang/commitdiff
Sema::CheckForFileScopedRedefinitions(): Make sure tentative decls of incomplete...
authorSteve Naroff <snaroff@apple.com>
Sun, 10 Aug 2008 15:20:13 +0000 (15:20 +0000)
committerSteve Naroff <snaroff@apple.com>
Sun, 10 Aug 2008 15:20:13 +0000 (15:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54612 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Sema/tentative-decls.c

index c776a5bfa5c9bd86f8bc1f71c41a304917a6f798..df4add2ea3e0ab50ee9d19fccc75abb0cc005f5d 100644 (file)
@@ -391,6 +391,7 @@ bool Sema::isTentativeDefinition(VarDecl *VD) {
 /// when dealing with C "tentative" external object definitions (C99 6.9.2).
 void Sema::CheckForFileScopedRedefinitions(Scope *S, VarDecl *VD) {
   bool VDIsTentative = isTentativeDefinition(VD);
+  bool VDIsIncompleteArray = VD->getType()->isIncompleteArrayType();
   
   for (IdentifierResolver::iterator
        I = IdResolver.begin(VD->getIdentifier(), 
@@ -399,6 +400,14 @@ void Sema::CheckForFileScopedRedefinitions(Scope *S, VarDecl *VD) {
     if (*I != VD && IdResolver.isDeclInScope(*I, VD->getDeclContext(), S)) {
       VarDecl *OldDecl = dyn_cast<VarDecl>(*I);
       
+      // Handle the following case:
+      //   int a[10];
+      //   int a[];   - the code below makes sure we set the correct type. 
+      //   int a[11]; - this is an error, size isn't 10.
+      if (OldDecl && VDIsTentative && VDIsIncompleteArray && 
+          OldDecl->getType()->isConstantArrayType())
+        VD->setType(OldDecl->getType());
+      
       // Check for "tentative" definitions. We can't accomplish this in 
       // MergeVarDecl since the initializer hasn't been attached.
       if (!OldDecl || isTentativeDefinition(OldDecl) || VDIsTentative)
index 7a374e05533e5e924975e20004e9c726b8159bfd..288757af87285eda2027d1705ce153adbb2457a3 100644 (file)
@@ -27,6 +27,10 @@ extern int i4;
 int (*pToArray)[];
 int (*pToArray)[8];
 
+int redef[10];
+int redef[];  // expected-error{{previous definition is here}}
+int redef[11]; // expected-error{{redefinition of 'redef'}}
+
 void func() {
   extern int i1; // expected-error{{previous definition is here}}
   static int i1; // expected-error{{static declaration of 'i1' follows non-static declaration}}