From: Eli Friedman Date: Tue, 20 May 2008 05:25:56 +0000 (+0000) Subject: Be a bit more defensive in SemaInit. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d8dc2100487640d8f5ce53201fdcfac7b5ca32b2;p=clang Be a bit more defensive in SemaInit. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51301 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index d5378d30d5..20fa50731d 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -111,7 +111,8 @@ void InitListChecker::CheckExplicitInitList(InitListExpr *IList, QualType &T, diag::err_excess_initializers_in_char_array_initializer, IList->getInit(Index)->getSourceRange()); hadError = true; - } else { + } else if (!T->isIncompleteType()) { + // Don't warn for incomplete types, since we'll get an error elsewhere SemaRef->Diag(IList->getInit(Index)->getLocStart(), diag::warn_excess_initializers, IList->getInit(Index)->getSourceRange()); @@ -137,6 +138,11 @@ void InitListChecker::CheckListElementTypes(InitListExpr *IList, CheckArrayType(IList, DeclType, Index); else assert(0 && "Aggregate that isn't a function or array?!"); + } else if (DeclType->isVoidType()) { + // This is clearly invalid, so not much we can do here. Don't bother + // with a diagnostic; we'll give an error elsewhere. + Index++; + hadError = true; } else { // In C, all types are either scalars or aggregates, but // additional handling is needed here for C++ (and possibly others?). diff --git a/test/Sema/compound-literal.c b/test/Sema/compound-literal.c index 3a4192260b..80dd370962 100644 --- a/test/Sema/compound-literal.c +++ b/test/Sema/compound-literal.c @@ -25,4 +25,5 @@ struct Incomplete; struct Incomplete* I1 = &(struct Incomplete){1, 2, 3}; // -expected-error {{variable has incomplete type}} void IncompleteFunc(unsigned x) { struct Incomplete* I2 = (struct foo[x]){1, 2, 3}; // -expected-error {{variable-sized object may not be initialized}} + (void){1,2,3}; // -expected-error {{variable has incomplete type}} }