FieldDecl *OldField = FieldsWithMemberInitializers[I].first;
FieldDecl *NewField = FieldsWithMemberInitializers[I].second;
Expr *OldInit = OldField->getInClassInitializer();
- ExprResult NewInit = SubstExpr(OldInit, TemplateArgs);
-
- // If the initialization is no longer dependent, check it now.
- if ((OldField->getType()->isDependentType() || OldInit->isTypeDependent() ||
- OldInit->isValueDependent()) &&
- !NewField->getType()->isDependentType() &&
- !NewInit.get()->isTypeDependent() &&
- !NewInit.get()->isValueDependent()) {
- // FIXME: handle list-initialization
- SourceLocation EqualLoc = NewField->getLocation();
- NewInit = PerformCopyInitialization(
- InitializedEntity::InitializeMember(NewField), EqualLoc,
- NewInit.release());
-
- if (!NewInit.isInvalid()) {
- CheckImplicitConversions(NewInit.get(), EqualLoc);
-
- // C++0x [class.base.init]p7:
- // The initialization of each base and member constitutes a
- // full-expression.
- NewInit = MaybeCreateExprWithCleanups(NewInit);
- }
- }
- if (NewInit.isInvalid())
+ SourceLocation LParenLoc, RParenLoc;
+ ASTOwningVector<Expr*> NewArgs(*this);
+ if (InstantiateInitializer(OldInit, TemplateArgs, LParenLoc, NewArgs,
+ RParenLoc))
NewField->setInvalidDecl();
- else
- NewField->setInClassInitializer(NewInit.release());
+ else {
+ assert(NewArgs.size() == 1 && "wrong number of in-class initializers");
+ ActOnCXXInClassMemberInitializer(NewField, LParenLoc, NewArgs[0]);
+ }
}
if (!FieldsWithMemberInitializers.empty())
/// \brief Instantiate an initializer, breaking it into separate
/// initialization arguments.
///
-/// \param S The semantic analysis object.
-///
/// \param Init The initializer to instantiate.
///
/// \param TemplateArgs Template arguments to be substituted into the
/// \param NewArgs Will be filled in with the instantiation arguments.
///
/// \returns true if an error occurred, false otherwise
-static bool InstantiateInitializer(Sema &S, Expr *Init,
+bool Sema::InstantiateInitializer(Expr *Init,
const MultiLevelTemplateArgumentList &TemplateArgs,
- SourceLocation &LParenLoc,
- ASTOwningVector<Expr*> &NewArgs,
- SourceLocation &RParenLoc) {
+ SourceLocation &LParenLoc,
+ ASTOwningVector<Expr*> &NewArgs,
+ SourceLocation &RParenLoc) {
NewArgs.clear();
LParenLoc = SourceLocation();
RParenLoc = SourceLocation();
if (ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) {
LParenLoc = ParenList->getLParenLoc();
RParenLoc = ParenList->getRParenLoc();
- return S.SubstExprs(ParenList->getExprs(), ParenList->getNumExprs(),
- true, TemplateArgs, NewArgs);
+ return SubstExprs(ParenList->getExprs(), ParenList->getNumExprs(),
+ true, TemplateArgs, NewArgs);
}
if (CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init)) {
if (!isa<CXXTemporaryObjectExpr>(Construct)) {
- if (S.SubstExprs(Construct->getArgs(), Construct->getNumArgs(), true,
- TemplateArgs, NewArgs))
+ if (SubstExprs(Construct->getArgs(), Construct->getNumArgs(), true,
+ TemplateArgs, NewArgs))
return true;
// FIXME: Fake locations!
- LParenLoc = S.PP.getLocForEndOfToken(Init->getLocStart());
+ LParenLoc = PP.getLocForEndOfToken(Init->getLocStart());
RParenLoc = LParenLoc;
return false;
}
}
- ExprResult Result = S.SubstExpr(Init, TemplateArgs);
+ ExprResult Result = SubstExpr(Init, TemplateArgs);
if (Result.isInvalid())
return true;
// Instantiate the initializer.
SourceLocation LParenLoc, RParenLoc;
ASTOwningVector<Expr*> InitArgs(SemaRef);
- if (!InstantiateInitializer(SemaRef, D->getInit(), TemplateArgs, LParenLoc,
- InitArgs, RParenLoc)) {
+ if (!SemaRef.InstantiateInitializer(D->getInit(), TemplateArgs, LParenLoc,
+ InitArgs, RParenLoc)) {
bool TypeMayContainAuto = true;
// Attach the initializer to the declaration, if we have one.
if (InitArgs.size() == 0)
Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, I);
// Instantiate the initializer.
- if (InstantiateInitializer(*this, Init->getInit(), TemplateArgs,
+ if (InstantiateInitializer(Init->getInit(), TemplateArgs,
LParenLoc, NewArgs, RParenLoc)) {
AnyErrors = true;
break;
}
// Instantiate the initializer.
- if (InstantiateInitializer(*this, Init->getInit(), TemplateArgs,
+ if (InstantiateInitializer(Init->getInit(), TemplateArgs,
LParenLoc, NewArgs, RParenLoc)) {
AnyErrors = true;
continue;