[cfe-commits] r51301 - in /cfe/trunk: lib/Sema/SemaInit.cpp test/Sema/compound-literal.c
Eli Friedman
eli.friedman at gmail.com
Mon May 19 22:25:56 PDT 2008
Author: efriedma
Date: Tue May 20 00:25:56 2008
New Revision: 51301
URL: http://llvm.org/viewvc/llvm-project?rev=51301&view=rev
Log:
Be a bit more defensive in SemaInit.
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/Sema/compound-literal.c
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=51301&r1=51300&r2=51301&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Tue May 20 00:25:56 2008
@@ -111,7 +111,8 @@
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 @@
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?).
Modified: cfe/trunk/test/Sema/compound-literal.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/compound-literal.c?rev=51301&r1=51300&r2=51301&view=diff
==============================================================================
--- cfe/trunk/test/Sema/compound-literal.c (original)
+++ cfe/trunk/test/Sema/compound-literal.c Tue May 20 00:25:56 2008
@@ -25,4 +25,5 @@
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}}
}
More information about the cfe-commits
mailing list