aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaInit.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-03-20 00:32:56 +0000
committerDouglas Gregor <dgregor@apple.com>2009-03-20 00:32:56 +0000
commita6457963cf7ffe71498c408dd590d9d1acb9513c (patch)
treec747c6a2675d10c3dfd9471828811a82386d85e5 /lib/Sema/SemaInit.cpp
parent748d5d655d9df4e9f8b8ae93ecdd24d725cfb1b8 (diff)
Allow flexible array initializers that are not surrounded by
braces. We now build the appropriate fully-structured initializer list for such things. Per PR3618, verified that we're getting the right code generation. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67353 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaInit.cpp')
-rw-r--r--lib/Sema/SemaInit.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index e0d3b7e545..8a5e2c87d3 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -481,7 +481,8 @@ void InitListChecker::CheckImplicitInitList(InitListExpr *ParentIList,
StructuredSubobjectInitIndex,
TopLevelObject);
unsigned EndIndex = (Index == StartIndex? StartIndex : Index - 1);
-
+ StructuredSubobjectInitList->setType(T);
+
// Update the structured sub-object initializer so that it's ending
// range corresponds with the end of the last initializer it used.
if (EndIndex < ParentIList->getNumInits()) {
@@ -995,23 +996,35 @@ void InitListChecker::CheckStructUnionTypes(InitListExpr *IList,
}
if (Field == FieldEnd || !Field->getType()->isIncompleteArrayType() ||
- Index >= IList->getNumInits() ||
- !isa<InitListExpr>(IList->getInit(Index)))
+ Index >= IList->getNumInits())
return;
// Handle GNU flexible array initializers.
if (!TopLevelObject &&
- cast<InitListExpr>(IList->getInit(Index))->getNumInits() > 0) {
+ (!isa<InitListExpr>(IList->getInit(Index)) ||
+ cast<InitListExpr>(IList->getInit(Index))->getNumInits() > 0)) {
SemaRef.Diag(IList->getInit(Index)->getSourceRange().getBegin(),
diag::err_flexible_array_init_nonempty)
<< IList->getInit(Index)->getSourceRange().getBegin();
SemaRef.Diag(Field->getLocation(), diag::note_flexible_array_member)
<< *Field;
hadError = true;
+ ++Index;
+ return;
+ } else {
+ SemaRef.Diag(IList->getInit(Index)->getSourceRange().getBegin(),
+ diag::ext_flexible_array_init)
+ << IList->getInit(Index)->getSourceRange().getBegin();
+ SemaRef.Diag(Field->getLocation(), diag::note_flexible_array_member)
+ << *Field;
}
- CheckSubElementType(IList, Field->getType(), Index, StructuredList,
- StructuredIndex);
+ if (isa<InitListExpr>(IList->getInit(Index)))
+ CheckSubElementType(IList, Field->getType(), Index, StructuredList,
+ StructuredIndex);
+ else
+ CheckImplicitInitList(IList, Field->getType(), Index, StructuredList,
+ StructuredIndex);
}
/// @brief Check the well-formedness of a C99 designated initializer.