diff options
author | Steve Naroff <snaroff@apple.com> | 2008-08-10 15:20:13 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2008-08-10 15:20:13 +0000 |
commit | f855e6fbebb718a1cca75ec2efba12f3583fe614 (patch) | |
tree | 4cffb09d9cfd56549a779b80316ffe30d5ce96a9 /lib/Sema/SemaDecl.cpp | |
parent | 03db1b31dd926409b7defc1c90b66549464652c0 (diff) |
Sema::CheckForFileScopedRedefinitions(): Make sure tentative decls of incomplete array types are completed (and diagnosed properly).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54612 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index c776a5bfa5..df4add2ea3 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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) |