From: Eli Friedman Date: Thu, 10 Dec 2009 08:54:47 +0000 (+0000) Subject: Fix for PR5515: allow "merging" array bounds both forwards and backwards. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=153c33ed957b135a366178c61bbe22b6b1362a2a;p=clang Fix for PR5515: allow "merging" array bounds both forwards and backwards. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91044 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index bf6863bbf4..55a5e7b063 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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 OldArray @@ -1102,6 +1103,14 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) { = Context.getCanonicalType(New->getType())->getAs(); if (OldArray->getElementType() == NewArray->getElementType()) MergedT = New->getType(); + } else if (Old->getType()->isArrayType() && + New->getType()->isIncompleteArrayType()) { + CanQual OldArray + = Context.getCanonicalType(Old->getType())->getAs(); + CanQual NewArray + = Context.getCanonicalType(New->getType())->getAs(); + if (OldArray->getElementType() == NewArray->getElementType()) + MergedT = Old->getType(); } } else { MergedT = Context.mergeTypes(New->getType(), Old->getType()); diff --git a/test/SemaCXX/array-bound-merge.cpp b/test/SemaCXX/array-bound-merge.cpp new file mode 100644 index 0000000000..579c793368 --- /dev/null +++ b/test/SemaCXX/array-bound-merge.cpp @@ -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}}