[cfe-commits] r54614 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/Sema/SemaInit.cpp test/Sema/compound-literal.c
Steve Naroff
snaroff at apple.com
Sun Aug 10 09:05:50 PDT 2008
Author: snaroff
Date: Sun Aug 10 11:05:48 2008
New Revision: 54614
URL: http://llvm.org/viewvc/llvm-project?rev=54614&view=rev
Log:
InitListChecker::CheckListElementTypes(): Check for function types and issue an appropriate diagnostic.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/Sema/compound-literal.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=54614&r1=54613&r2=54614&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Sun Aug 10 11:05:48 2008
@@ -810,6 +810,8 @@
"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")
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=54614&r1=54613&r2=54614&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Sun Aug 10 11:05:48 2008
@@ -139,10 +139,11 @@
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
Modified: cfe/trunk/test/Sema/compound-literal.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/compound-literal.c?rev=54614&r1=54613&r2=54614&view=diff
==============================================================================
--- cfe/trunk/test/Sema/compound-literal.c (original)
+++ cfe/trunk/test/Sema/compound-literal.c Sun Aug 10 11:05:48 2008
@@ -29,4 +29,5 @@
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)')}}
}
More information about the cfe-commits
mailing list