diff options
author | Steve Naroff <snaroff@apple.com> | 2008-08-10 16:05:48 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2008-08-10 16:05:48 +0000 |
commit | 613535273b90dc5cbd0f9fa056dedc93801ea35a (patch) | |
tree | f6cd10d324928e54e156e12f276b2a626a157fc6 | |
parent | d4d46cd61673202d6c32c51a8bc0abc937bff808 (diff) |
InitListChecker::CheckListElementTypes(): Check for function types and issue an appropriate diagnostic.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54614 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticKinds.def | 2 | ||||
-rw-r--r-- | lib/Sema/SemaInit.cpp | 7 | ||||
-rw-r--r-- | test/Sema/compound-literal.c | 1 |
3 files changed, 7 insertions, 3 deletions
diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index 9552c332ac..a10ceaa19e 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -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") diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index bc38de3633..a2add34238 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -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 diff --git a/test/Sema/compound-literal.c b/test/Sema/compound-literal.c index 5f31ae6648..1de0e0bec4 100644 --- a/test/Sema/compound-literal.c +++ b/test/Sema/compound-literal.c @@ -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)')}} } |