InitListChecker::CheckListElementTypes(): Check for function types and issue an appropriate diagnostic.

llvm-svn: 54614
This commit is contained in:
Steve Naroff 2008-08-10 16:05:48 +00:00
parent 63ebb3cd3e
commit eaf5853004
3 changed files with 7 additions and 3 deletions

View File

@ -810,6 +810,8 @@ DIAG(err_empty_scalar_initializer, ERROR,
"scalar initializer cannot be empty")
DIAG(err_illegal_initializer, ERROR,
"illegal initializer (only variables can be initialized)")
DIAG(err_illegal_initializer_type, ERROR,
"illegal initializer type ('%0')")
DIAG(err_implicit_empty_initializer, ERROR,
"initializer for aggregate with no elements requires explicit braces")

View File

@ -139,10 +139,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.
} else if (DeclType->isVoidType() || DeclType->isFunctionType()) {
// This type is invalid, issue a diagnostic.
Index++;
SemaRef->Diag(IList->getLocStart(), diag::err_illegal_initializer_type,
DeclType.getAsString());
hadError = true;
} else {
// In C, all types are either scalars or aggregates, but

View File

@ -29,4 +29,5 @@ struct Incomplete* I1 = &(struct Incomplete){1, 2, 3}; // -expected-error {{vari
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}}
(void(void)) { 0 }; // -expected-error{{illegal initializer type ('void (void)')}}
}