]> granicus.if.org Git - clang/commitdiff
InitListChecker::CheckListElementTypes(): Check for function types and issue an appro...
authorSteve Naroff <snaroff@apple.com>
Sun, 10 Aug 2008 16:05:48 +0000 (16:05 +0000)
committerSteve Naroff <snaroff@apple.com>
Sun, 10 Aug 2008 16:05:48 +0000 (16:05 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54614 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticKinds.def
lib/Sema/SemaInit.cpp
test/Sema/compound-literal.c

index 9552c332ac9e277541ce7531ce195265c2fdb206..a10ceaa19e49d36c0efa8aa96f3f2931b4245b84 100644 (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")
 
index bc38de3633a6741a105912bdc421a0d0cb0aa839..a2add3423822a20f10c7ef7d6cee2acd9da77682 100644 (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
index 5f31ae6648cf4782c0d023286692d42899de4a41..1de0e0bec44084fbc6e296b387a62523548a9cbf 100644 (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)')}}
 }