Make sure template argument deduction is consistently performed in an unevaluated context.

llvm-svn: 150049
This commit is contained in:
Eli Friedman 2012-02-08 03:07:05 +00:00
parent 95c0feb5e0
commit 77dcc726de
2 changed files with 25 additions and 9 deletions

View File

@ -2019,7 +2019,8 @@ FinishTemplateArgumentDeduction(Sema &S,
const TemplateArgumentList &TemplateArgs,
SmallVectorImpl<DeducedTemplateArgument> &Deduced,
TemplateDeductionInfo &Info) {
// Trap errors.
// Unevaluated SFINAE context.
EnterExpressionEvaluationContext Unevaluated(S, Sema::Unevaluated);
Sema::SFINAETrap Trap(S);
Sema::ContextRAII SavedContext(S, Partial);
@ -2145,7 +2146,11 @@ Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
// argument list if the template arguments of the partial
// specialization can be deduced from the actual template argument
// list (14.8.2).
// Unevaluated SFINAE context.
EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated);
SFINAETrap Trap(*this);
SmallVector<DeducedTemplateArgument, 4> Deduced;
Deduced.resize(Partial->getTemplateParameters()->size());
if (TemplateDeductionResult Result
@ -2226,8 +2231,8 @@ Sema::SubstituteExplicitTemplateArguments(
return TDK_Success;
}
// Substitution of the explicit template arguments into a function template
/// is a SFINAE context. Trap any errors that might occur.
// Unevaluated SFINAE context.
EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated);
SFINAETrap Trap(*this);
// C++ [temp.arg.explicit]p3:
@ -2449,8 +2454,8 @@ Sema::FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate,
TemplateParameterList *TemplateParams
= FunctionTemplate->getTemplateParameters();
// Template argument deduction for function templates in a SFINAE context.
// Trap any errors that might occur.
// Unevaluated SFINAE context.
EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated);
SFINAETrap Trap(*this);
// Enter a new template instantiation context while we instantiate the
@ -3172,8 +3177,8 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
NumExplicitlySpecified = Deduced.size();
}
// Template argument deduction for function templates in a SFINAE context.
// Trap any errors that might occur.
// Unevaluated SFINAE context.
EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated);
SFINAETrap Trap(*this);
Deduced.resize(TemplateParams->size());
@ -3257,8 +3262,8 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
A = A.getUnqualifiedType();
}
// Template argument deduction for function templates in a SFINAE context.
// Trap any errors that might occur.
// Unevaluated SFINAE context.
EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated);
SFINAETrap Trap(*this);
// C++ [temp.deduct.conv]p1:

View File

@ -170,3 +170,14 @@ namespace cxx11_odr_rules {
b();
}
}
namespace OverloadUse {
namespace {
void f();
void f(int); // expected-warning {{function 'OverloadUse::<anonymous namespace>::f' has internal linkage but is not defined}}
}
template<void x()> void t(int*) { x(); }
template<void x(int)> void t(long*) { x(10); } // expected-note {{used here}}
void g() { long a; t<f>(&a); }
}