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 | d24c306e693a1013b233f062291e87d49fa8a580 (patch) | |
tree | 751cbb4e859930a06211c16e4a928aca521880b0 /lib/Sema/SemaDeclCXX.cpp | |
parent | 147545d698972cfd34ece30a5d55e8180784161e (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141543 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDeclCXX.cpp')
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 6c84c30663..247d8dc5bb 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/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); |