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
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 6c84c30..247d8dc 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -9088,6 +9088,7 @@
// 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 @@
= 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);