summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-10-15 23:53:28 +0000
committerDouglas Gregor <dgregor@apple.com>2010-10-15 23:53:28 +0000
commit1f81ced14cc29a8bb5e52ce11d7ebe204c8cc138 (patch)
tree21b73fde2bcec42285f04ba7c823f08d0253e873 /clang/lib
parentad5f98a9b224876465ea16c097d6ec889491351c (diff)
downloadbcm5719-llvm-1f81ced14cc29a8bb5e52ce11d7ebe204c8cc138.tar.gz
bcm5719-llvm-1f81ced14cc29a8bb5e52ce11d7ebe204c8cc138.zip
Allow list-initialization of a local variable of class type with a
flexible array member, so long as the flexibility array member is either not initialized or is initialized with an empty initializer list. Fixes <rdar://problem/8540437>. llvm-svn: 116647
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 23721e5d992..e7714521c84 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -4395,9 +4395,19 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
// global/static definition.
if (VDecl->hasLocalStorage())
if (const RecordType *RT = VDecl->getType()->getAs<RecordType>())
- if (RT->getDecl()->hasFlexibleArrayMember() && isa<InitListExpr>(Init)) {
- Diag(VDecl->getLocation(), diag::err_nonstatic_flexible_variable);
- VDecl->setInvalidDecl();
+ if (RT->getDecl()->hasFlexibleArrayMember()) {
+ // Check whether the initializer tries to initialize the flexible
+ // array member itself to anything other than an empty initializer list.
+ if (InitListExpr *ILE = dyn_cast<InitListExpr>(Init)) {
+ unsigned Index = std::distance(RT->getDecl()->field_begin(),
+ RT->getDecl()->field_end()) - 1;
+ if (Index < ILE->getNumInits() &&
+ !(isa<InitListExpr>(ILE->getInit(Index)) &&
+ cast<InitListExpr>(ILE->getInit(Index))->getNumInits() == 0)) {
+ Diag(VDecl->getLocation(), diag::err_nonstatic_flexible_variable);
+ VDecl->setInvalidDecl();
+ }
+ }
}
// Check any implicit conversions within the expression.
OpenPOWER on IntegriCloud