/// This allows ActOnDeclarator to register "xx" prior to parsing the
/// initializer. The declaration above should still result in a warning,
/// since the reference to "xx" is uninitialized.
- virtual void AddInitializerToDecl(DeclPtrTy Dcl, FullExprArg Init) {
+ virtual void AddInitializerToDecl(DeclPtrTy Dcl, ExprArg Init) {
return;
}
/// This allows ActOnDeclarator to register "xx" prior to parsing the
/// initializer. The declaration above should still result in a warning,
/// since the reference to "xx" is uninitialized.
- virtual void AddInitializerToDecl(DeclPtrTy Dcl, FullExprArg Init) {
+ virtual void AddInitializerToDecl(DeclPtrTy Dcl, ExprArg Init) {
Out << __FUNCTION__ << "\n";
}
SkipUntil(tok::semi, true, true);
return DeclPtrTy();
}
- Actions.AddInitializerToDecl(ThisDecl, Actions.FullExpr(Init));
+ Actions.AddInitializerToDecl(ThisDecl, move(Init));
}
} else if (Tok.is(tok::l_paren)) {
// Parse C++ direct initializer: '(' expression-list ')'
// argument locations.
llvm::DenseMap<ParmVarDecl *,SourceLocation> UnparsedDefaultArgLocs;
- virtual void AddInitializerToDecl(DeclPtrTy dcl, FullExprArg init);
+ virtual void AddInitializerToDecl(DeclPtrTy dcl, ExprArg init);
void AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit);
void ActOnUninitializedDecl(DeclPtrTy dcl, bool TypeContainsUndeducedAuto);
virtual void SetDeclDeleted(DeclPtrTy dcl, SourceLocation DelLoc);
CXXConstructorDecl *Constructor,
QualType DeclInitType,
Expr **Exprs, unsigned NumExprs);
-
+
+ Expr *BuildCXXConstructExpr(QualType DeclInitType,
+ CXXConstructorDecl *Constructor,
+ Expr **Exprs, unsigned NumExprs);
+
/// BuildCXXConstructExpr - Creates a complete call to a constructor,
/// including handling of its default argument expressions.
Expr *BuildCXXConstructExpr(QualType DeclInitType,
CXXConstructorDecl *Constructor,
bool Elidable,
Expr **Exprs, unsigned NumExprs);
-
- Expr *BuildCXXCopyConstructExpr(Expr *Expr);
/// FinalizeVarWithDestructor - Prepare for calling destructor on the
/// constructed variable.
return true;
}
-void Sema::AddInitializerToDecl(DeclPtrTy dcl, FullExprArg init) {
- AddInitializerToDecl(dcl, init.release(), /*DirectInit=*/false);
+void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init) {
+ AddInitializerToDecl(dcl, move(init), /*DirectInit=*/false);
}
/// AddInitializerToDecl - Adds the initializer Init to the
Init->setType(DclT);
}
+ Init = MaybeCreateCXXExprWithTemporaries(Init,
+ /*ShouldDestroyTemporaries=*/true);
// Attach the initializer to the decl.
VDecl->setInit(Context, Init);
CopyConstructor->setUsed();
}
+Expr *Sema::BuildCXXConstructExpr(QualType DeclInitType,
+ CXXConstructorDecl *Constructor,
+ Expr **Exprs, unsigned NumExprs) {
+ bool Elidable = false;
+
+ // [class.copy]p15:
+ // Whenever a temporary class object is copied using a copy constructor, and
+ // this object and the copy have the same cv-unqualified type, an
+ // implementation is permitted to treat the original and the copy as two
+ // different ways of referring to the same object and not perform a copy at
+ //all, even if the class copy constructor or destructor have side effects.
+
+ // FIXME: Is this enough?
+ if (Constructor->isCopyConstructor(Context) && NumExprs == 1) {
+ Expr *E = Exprs[0];
+ while (CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E))
+ E = BE->getSubExpr();
+
+ if (isa<CallExpr>(E) || isa<CXXTemporaryObjectExpr>(E))
+ Elidable = true;
+ }
+
+ return BuildCXXConstructExpr(DeclInitType, Constructor, Elidable,
+ Exprs, NumExprs);
+}
+
/// BuildCXXConstructExpr - Creates a complete call to a constructor,
/// including handling of its default argument expressions.
Expr *Sema::BuildCXXConstructExpr(QualType DeclInitType,
QualType DeclInitType,
Expr **Exprs, unsigned NumExprs) {
Expr *Temp = BuildCXXConstructExpr(DeclInitType, Constructor,
- false, Exprs, NumExprs);
+ Exprs, NumExprs);
MarkDeclarationReferenced(VD->getLocation(), Constructor);
Temp = MaybeCreateCXXExprWithTemporaries(Temp, /*DestroyTemps=*/true);
VD->setInit(Context, Temp);
// FIXME: When can ToType be a reference type?
assert(!ToType->isReferenceType());
- // FIXME: Keep track of whether the copy constructor is elidable or not.
- bool Elidable = (isa<CallExpr>(From) ||
- isa<CXXTemporaryObjectExpr>(From));
- From = BuildCXXConstructExpr(ToType, SCS.CopyConstructor,
- Elidable, &From, 1);
+ From = BuildCXXConstructExpr(ToType, SCS.CopyConstructor, &From, 1);
return false;
}
DirectInit? IK_Direct : IK_Copy);
if (!Constructor)
return true;
- bool Elidable = (isa<CallExpr>(Init) ||
- isa<CXXTemporaryObjectExpr>(Init));
- Init = BuildCXXConstructExpr(DeclType, Constructor, Elidable, &Init, 1);
- Init = MaybeCreateCXXExprWithTemporaries(Init, /*DestroyTemps=*/true);
+ Init = BuildCXXConstructExpr(DeclType, Constructor, &Init, 1);
return false;
}