Special-case default argument expression in instantiation. This should fix PR4301. Doug, please double-check my assumptions. Read the PR for more details.

llvm-svn: 86465
This commit is contained in:
Sebastian Redl 2009-11-08 13:56:19 +00:00
parent b0a05f7ca1
commit 14236c8e82
2 changed files with 35 additions and 0 deletions

View File

@ -427,6 +427,9 @@ namespace {
Sema::OwningExprResult TransformDeclRefExpr(DeclRefExpr *E,
bool isAddressOfOperand);
Sema::OwningExprResult TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E,
bool isAddressOfOperand);
/// \brief Transforms a template type parameter type by performing
/// substitution of the corresponding template type argument.
QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB,
@ -648,6 +651,15 @@ TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E,
isAddressOfOperand);
}
Sema::OwningExprResult TemplateInstantiator::TransformCXXDefaultArgExpr(
CXXDefaultArgExpr *E, bool isAddressOfOperand) {
assert(!cast<FunctionDecl>(E->getParam()->getDeclContext())->
getDescribedFunctionTemplate() &&
"Default arg expressions are never formed in dependent cases.");
return SemaRef.Owned(E->Retain());
}
QualType
TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB,
TemplateTypeParmTypeLoc TL) {

View File

@ -108,3 +108,26 @@ struct D {
};
D::D() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
}
// PR5301
namespace pr5301 {
void f(int, int = 0);
template <typename T>
void g(T, T = 0);
template <int I>
void i(int a = I);
template <typename T>
void h(T t) {
f(0);
g(1);
g(t);
i<2>();
}
void test() {
h(0);
}
}