CXXConstructorDecl *Constructor,
QualType DeclInitType,
Expr **Exprs, unsigned NumExprs);
+
+ /// BuildCXXConstructExpr - Creates a complete call to a constructor,
+ /// including handling of its default argument expressions.
+ Expr * BuildCXXConstructExpr(ASTContext &C,
+ QualType DeclInitType,
+ CXXConstructorDecl *Constructor,
+ bool Elidable,
+ Expr **Exprs, unsigned NumExprs);
/// FinalizeVarWithDestructor - Prepare for calling destructor on the
/// constructed variable.
CopyConstructor->setUsed();
}
-void Sema::InitializeVarWithConstructor(VarDecl *VD,
- CXXConstructorDecl *Constructor,
- QualType DeclInitType,
- Expr **Exprs, unsigned NumExprs) {
- CXXConstructExpr *Temp = CXXConstructExpr::Create(Context, DeclInitType,
+/// BuildCXXConstructExpr - Creates a complete call to a constructor,
+/// including handling of its default argument expressions.
+Expr *Sema::BuildCXXConstructExpr(ASTContext &C,
+ QualType DeclInitType,
+ CXXConstructorDecl *Constructor,
+ bool Elidable,
+ Expr **Exprs, unsigned NumExprs) {
+ CXXConstructExpr *Temp = CXXConstructExpr::Create(C, DeclInitType,
Constructor,
- false, Exprs, NumExprs);
+ Elidable, Exprs, NumExprs);
// default arguments must be added to constructor call expression.
FunctionDecl *FDecl = cast<FunctionDecl>(Constructor);
unsigned NumArgsInProto = FDecl->param_size();
for (unsigned I = 0, N = E->getNumTemporaries(); I != N; ++I)
ExprTemporaries.push_back(E->getTemporary(I));
}
- Expr *Arg = new (Context) CXXDefaultArgExpr(FDecl->getParamDecl(j));
+ Expr *Arg = new (C) CXXDefaultArgExpr(FDecl->getParamDecl(j));
Temp->setArg(j, Arg);
}
-
+ return Temp;
+}
+
+void Sema::InitializeVarWithConstructor(VarDecl *VD,
+ CXXConstructorDecl *Constructor,
+ QualType DeclInitType,
+ Expr **Exprs, unsigned NumExprs) {
+ Expr *Temp = BuildCXXConstructExpr(Context,
+ DeclInitType, Constructor,
+ false, Exprs, NumExprs);
MarkDeclarationReferenced(VD->getLocation(), Constructor);
VD->setInit(Context, Temp);
}
assert(!ToType->isReferenceType());
// FIXME: Keep track of whether the copy constructor is elidable or not.
- From = CXXConstructExpr::Create(Context, ToType,
- SCS.CopyConstructor, false, &From, 1);
+ From = BuildCXXConstructExpr(Context,
+ ToType, SCS.CopyConstructor, false, &From, 1);
return false;
}
--- /dev/null
+// RUN: clang-cc %s -emit-llvm -o %t &&
+// RUN: grep 'call void @_ZN1XC1ERK1Xiii' %t | count 3
+
+extern "C" int printf(...);
+
+
+struct C {
+ C() : iC(6) {}
+ int iC;
+};
+
+int foo() {
+ return 6;
+};
+
+class X { // ...
+public:
+ X(int) {}
+ X(const X&, int i = 1, int j = 2, int k = foo()) {
+ printf("X(const X&, %d, %d, %d)\n", i, j, k);
+ }
+};
+
+int main()
+{
+ X a(1);
+ X b(a, 2);
+ X c = b;
+ X d(a, 5, 6);
+}