aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-05-29 20:20:05 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-05-29 20:20:05 +0000
commite540858b289b23653bcb23646f135729203635cb (patch)
tree274b8a85a07cc4811f9d3f765fd97dd9ac21dda1
parent587cbdfd95f4b0aaccc14b31f5debe85d5daf7ed (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72588 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaInit.cpp15
-rw-r--r--test/Sema/array-init.c2
2 files changed, 11 insertions, 6 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index fada7fe0ad..6f71e1b3f7 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -529,15 +529,16 @@ void InitListChecker::CheckExplicitInitList(InitListExpr *IList, QualType &T,
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 @@ void InitListChecker::CheckExplicitInitList(InitListExpr *IList, QualType &T,
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();
diff --git a/test/Sema/array-init.c b/test/Sema/array-init.c
index dfaaa87ef5..50148a83ae 100644
--- a/test/Sema/array-init.c
+++ b/test/Sema/array-init.c
@@ -261,3 +261,5 @@ void test_matrix() {
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}}