[cfe-commits] r91044 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaCXX/array-bound-merge.cpp
Eli Friedman
eli.friedman at gmail.com
Thu Dec 10 00:54:47 PST 2009
Author: efriedma
Date: Thu Dec 10 02:54:47 2009
New Revision: 91044
URL: http://llvm.org/viewvc/llvm-project?rev=91044&view=rev
Log:
Fix for PR5515: allow "merging" array bounds both forwards and backwards.
Added:
cfe/trunk/test/SemaCXX/array-bound-merge.cpp
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=91044&r1=91043&r2=91044&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Dec 10 02:54:47 2009
@@ -1090,10 +1090,11 @@
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 @@
= 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());
Added: cfe/trunk/test/SemaCXX/array-bound-merge.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/array-bound-merge.cpp?rev=91044&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/array-bound-merge.cpp (added)
+++ cfe/trunk/test/SemaCXX/array-bound-merge.cpp Thu Dec 10 02:54:47 2009
@@ -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}}
More information about the cfe-commits
mailing list