Fix for PR5515: allow "merging" array bounds both forwards and backwards.

llvm-svn: 91044
This commit is contained in:
Eli Friedman 2009-12-10 08:54:47 +00:00
parent d011893e86
commit e919e382a4
2 changed files with 22 additions and 4 deletions

View File

@ -1090,10 +1090,11 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) {
if (getLangOptions().CPlusPlus) {
if (Context.hasSameType(New->getType(), Old->getType()))
MergedT = New->getType();
// C++ [basic.types]p7:
// [...] The declared type of an array object might be an array of
// unknown size and therefore be incomplete at one point in a
// translation unit and complete later on; [...]
// C++ [basic.link]p10:
// [...] the types specified by all declarations referring to a given
// object or function shall be identical, except that declarations for an
// array object can specify array types that differ by the presence or
// absence of a major array bound (8.3.4).
else if (Old->getType()->isIncompleteArrayType() &&
New->getType()->isArrayType()) {
CanQual<ArrayType> OldArray
@ -1102,6 +1103,14 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) {
= Context.getCanonicalType(New->getType())->getAs<ArrayType>();
if (OldArray->getElementType() == NewArray->getElementType())
MergedT = New->getType();
} else if (Old->getType()->isArrayType() &&
New->getType()->isIncompleteArrayType()) {
CanQual<ArrayType> OldArray
= Context.getCanonicalType(Old->getType())->getAs<ArrayType>();
CanQual<ArrayType> NewArray
= Context.getCanonicalType(New->getType())->getAs<ArrayType>();
if (OldArray->getElementType() == NewArray->getElementType())
MergedT = Old->getType();
}
} else {
MergedT = Context.mergeTypes(New->getType(), Old->getType());

View File

@ -0,0 +1,9 @@
// RUN: clang-cc -fsyntax-only -verify %s
// PR5515
extern int a[];
int a[10];
extern int b[10];
int b[];
extern int c[1];
int c[] = {1,2}; // expected-error {{excess elements in array initializer}}