[cfe-commits] r72588 - in /cfe/trunk: lib/Sema/SemaInit.cpp test/Sema/array-init.c
Eli Friedman
eli.friedman at gmail.com
Fri May 29 13:20:05 PDT 2009
Author: efriedma
Date: Fri May 29 15:20:05 2009
New Revision: 72588
URL: http://llvm.org/viewvc/llvm-project?rev=72588&view=rev
Log:
Make sure we don't give the wrong warning, and make sure not to set
hadError (suppressing future diagnostics) if we didn't print an
error.
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/Sema/array-init.c
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=72588&r1=72587&r2=72588&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri May 29 15:20:05 2009
@@ -529,15 +529,16 @@
if (Index < IList->getNumInits()) {
// We have leftover initializers
- if (IList->getNumInits() > 0 &&
- IsStringInit(IList->getInit(Index), T, SemaRef.Context)) {
+ if (StructuredIndex == 1 &&
+ IsStringInit(StructuredList->getInit(0), T, SemaRef.Context)) {
unsigned DK = diag::warn_excess_initializers_in_char_array_initializer;
- if (SemaRef.getLangOptions().CPlusPlus)
+ if (SemaRef.getLangOptions().CPlusPlus) {
DK = diag::err_excess_initializers_in_char_array_initializer;
+ hadError = true;
+ }
// Special-case
SemaRef.Diag(IList->getInit(Index)->getLocStart(), DK)
<< IList->getInit(Index)->getSourceRange();
- hadError = true;
} else if (!T->isIncompleteType()) {
// Don't complain for incomplete types, since we'll get an error
// elsewhere
@@ -550,8 +551,10 @@
4;
unsigned DK = diag::warn_excess_initializers;
- if (SemaRef.getLangOptions().CPlusPlus)
- DK = diag::err_excess_initializers;
+ if (SemaRef.getLangOptions().CPlusPlus) {
+ DK = diag::err_excess_initializers;
+ hadError = true;
+ }
SemaRef.Diag(IList->getInit(Index)->getLocStart(), DK)
<< initKind << IList->getInit(Index)->getSourceRange();
Modified: cfe/trunk/test/Sema/array-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/array-init.c?rev=72588&r1=72587&r2=72588&view=diff
==============================================================================
--- cfe/trunk/test/Sema/array-init.c (original)
+++ cfe/trunk/test/Sema/array-init.c Fri May 29 15:20:05 2009
@@ -261,3 +261,5 @@
13.0f, 14.0f, 15.0f, 16.0f
};
}
+
+char badchararray[1] = { badchararray[0], "asdf" }; // expected-warning {{excess elements in array initializer}} expected-error {{initializer element is not a compile-time constant}}
More information about the cfe-commits
mailing list