aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Sema/SemaInit.cpp8
-rw-r--r--test/Sema/compound-literal.c1
2 files changed, 8 insertions, 1 deletions
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}}
}