diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-10-10 16:05:18 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-10-10 16:05:18 +0000 |
commit | b06fa540e86251a3a7c3d0104def4d1b25fae7fc (patch) | |
tree | 5c7d4ed81258b1cd9cb46bd286267f2fd1452ed6 /clang/lib/Sema/SemaDeclCXX.cpp | |
parent | 728d00b8e70e732b80fa2f533424c70f9dd7dd99 (diff) | |
download | bcm5719-llvm-b06fa540e86251a3a7c3d0104def4d1b25fae7fc.tar.gz bcm5719-llvm-b06fa540e86251a3a7c3d0104def4d1b25fae7fc.zip |
When adding a direct initializer to a declaration, allow the
initializer to update the type of the declaration. For example, this
allows us to determine the size of an incomplete array from its
initializer. Fixes PR10288.
llvm-svn: 141543
Diffstat (limited to 'clang/lib/Sema/SemaDeclCXX.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 6c84c306631..247d8dc5bba 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -9088,6 +9088,7 @@ void Sema::AddCXXDirectInitializerToDecl(Decl *RealDecl, // class type. if (!VDecl->getType()->isDependentType() && + !VDecl->getType()->isIncompleteArrayType() && RequireCompleteType(VDecl->getLocation(), VDecl->getType(), diag::err_typecheck_decl_incomplete_type)) { VDecl->setInvalidDecl(); @@ -9163,14 +9164,19 @@ void Sema::AddCXXDirectInitializerToDecl(Decl *RealDecl, = InitializationKind::CreateDirect(VDecl->getLocation(), LParenLoc, RParenLoc); + QualType T = VDecl->getType(); InitializationSequence InitSeq(*this, Entity, Kind, Exprs.get(), Exprs.size()); - ExprResult Result = InitSeq.Perform(*this, Entity, Kind, move(Exprs)); + ExprResult Result = InitSeq.Perform(*this, Entity, Kind, move(Exprs), &T); if (Result.isInvalid()) { VDecl->setInvalidDecl(); return; + } else if (T != VDecl->getType()) { + VDecl->setType(T); + Result.get()->setType(T); } + Expr *Init = Result.get(); CheckImplicitConversions(Init, LParenLoc); |