Fix an inconsistency in the syntactic form of InitListExpr in case of initialization that involves a ConstructorConversion

llvm-svn: 146766
This commit is contained in:
Nicola Gigante 2011-12-16 22:57:37 +00:00
parent eb3ce7c3db
commit 3533eb4f5c
1 changed files with 37 additions and 6 deletions

View File

@ -171,6 +171,9 @@ class InitListChecker {
bool hadError;
bool VerifyOnly; // no diagnostics, no structure building
bool AllowBraceElision;
Expr *LastCheckedSubobject;
unsigned LastCheckedSubobjectIndex;
std::map<InitListExpr *, InitListExpr *> SyntacticToSemantic;
InitListExpr *FullyStructuredList;
@ -470,7 +473,8 @@ InitListChecker::FillInValueInitializations(const InitializedEntity &Entity,
InitListChecker::InitListChecker(Sema &S, const InitializedEntity &Entity,
InitListExpr *IL, QualType &T,
bool VerifyOnly, bool AllowBraceElision)
: SemaRef(S), VerifyOnly(VerifyOnly), AllowBraceElision(AllowBraceElision) {
: SemaRef(S), VerifyOnly(VerifyOnly), AllowBraceElision(AllowBraceElision),
LastCheckedSubobject(0), LastCheckedSubobjectIndex(0) {
hadError = false;
unsigned newIndex = 0;
@ -792,13 +796,40 @@ void InitListChecker::CheckSubElementType(const InitializedEntity &Entity,
if (Seq) {
if (!VerifyOnly) {
ExprResult Result =
Seq.Perform(SemaRef, Entity, Kind, MultiExprArg(&expr, 1));
if (Result.isInvalid())
hadError = true;
// struct S {
// S(int);
// };
//
// S s[] = { [0 ... 2] = 3 };
//
// In code like this, we want to perform the initialization and then
// update the syntactic list with the result. However, we reach this
// point once for each subobject, but the update needs
// to be done only once for each syntactic element. For this reason,
// the initialization result and its syntactic Index are cached in
// LastCheckedSubobject and LastCheckedSubobjectIndex and reused until
// we move to the next Index.
Expr *ResultExpr = LastCheckedSubobject;
if (!ResultExpr || Index != LastCheckedSubobjectIndex) {
ExprResult Result = Seq.Perform(SemaRef, Entity, Kind, MultiExprArg(&expr, 1));
if (Result.isInvalid()) {
hadError = true;
ResultExpr = 0;
} else {
ResultExpr = Result.takeAs<Expr>();
}
LastCheckedSubobject = ResultExpr;
LastCheckedSubobjectIndex = Index;
}
// Update the syntactic list
IList->setInit(Index, ResultExpr);
UpdateStructuredListElement(StructuredList, StructuredIndex,
Result.takeAs<Expr>());
ResultExpr);
}
++Index;
return;