[cfe-commits] r79984 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/SemaTemplate/default-expr-arguments.cpp
Anders Carlsson
andersca at mac.com
Tue Aug 25 06:07:09 PDT 2009
Author: andersca
Date: Tue Aug 25 08:07:08 2009
New Revision: 79984
URL: http://llvm.org/viewvc/llvm-project?rev=79984&view=rev
Log:
Improved support for default arguments in constructors for class templates.
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaTemplate/default-expr-arguments.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=79984&r1=79983&r2=79984&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Aug 25 08:07:08 2009
@@ -2442,29 +2442,28 @@
bool Elidable,
Expr **Exprs,
unsigned NumExprs) {
- CXXConstructExpr *Temp = CXXConstructExpr::Create(Context, DeclInitType,
- Constructor,
- Elidable, Exprs, NumExprs);
+ ExprOwningPtr<CXXConstructExpr> Temp(this,
+ CXXConstructExpr::Create(Context,
+ DeclInitType,
+ Constructor,
+ Elidable,
+ Exprs,
+ NumExprs));
// default arguments must be added to constructor call expression.
FunctionDecl *FDecl = cast<FunctionDecl>(Constructor);
unsigned NumArgsInProto = FDecl->param_size();
for (unsigned j = NumExprs; j != NumArgsInProto; j++) {
- Expr *DefaultExpr = FDecl->getParamDecl(j)->getDefaultArg();
-
- // If the default expression creates temporaries, we need to
- // push them to the current stack of expression temporaries so they'll
- // be properly destroyed.
- if (CXXExprWithTemporaries *E
- = dyn_cast_or_null<CXXExprWithTemporaries>(DefaultExpr)) {
- assert(!E->shouldDestroyTemporaries() &&
- "Can't destroy temporaries in a default argument expr!");
- for (unsigned I = 0, N = E->getNumTemporaries(); I != N; ++I)
- ExprTemporaries.push_back(E->getTemporary(I));
- }
- Expr *Arg = CXXDefaultArgExpr::Create(Context, FDecl->getParamDecl(j));
- Temp->setArg(j, Arg);
+ ParmVarDecl *Param = FDecl->getParamDecl(j);
+
+ OwningExprResult ArgExpr =
+ BuildCXXDefaultArgExpr(/*FIXME:*/SourceLocation(),
+ FDecl, Param);
+ if (ArgExpr.isInvalid())
+ return ExprError();
+
+ Temp->setArg(j, ArgExpr.takeAs<Expr>());
}
- return Owned(Temp);
+ return move(Temp);
}
bool Sema::InitializeVarWithConstructor(VarDecl *VD,
Modified: cfe/trunk/test/SemaTemplate/default-expr-arguments.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/default-expr-arguments.cpp?rev=79984&r1=79983&r2=79984&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/default-expr-arguments.cpp (original)
+++ cfe/trunk/test/SemaTemplate/default-expr-arguments.cpp Tue Aug 25 08:07:08 2009
@@ -18,3 +18,11 @@
f3(10);
f3(S()); // expected-note{{in instantiation of default argument for 'f3<struct S>' required here}}
}
+
+template<typename T> struct F {
+ F(T t = 10);
+};
+
+void g2() {
+ F<int> f;
+}
More information about the cfe-commits
mailing list