From e540858b289b23653bcb23646f135729203635cb Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Fri, 29 May 2009 20:20:05 +0000 Subject: [PATCH] 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 --- lib/Sema/SemaInit.cpp | 15 +++++++++------ test/Sema/array-init.c | 2 ++ 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}} -- 2.40.0