Fix assertion failure on MaybeODRUseExprs.

In VisitNonTypeTemplateParamDecl, before SubstExpr with the default argument,
we should create a ConstantEvaluated ExpressionEvaluationContext. Without this,
it is possible to use a PotentiallyEvaluated ExpressionEvaluationContext; and
MaybeODRUseExprs will not be cleared when popping the context, causing
assertion failure.

This is similar to how we handle the context before SubstExpr with the
default argument, in SubstDefaultTemplateArgument.

Part of PR13986.
rdar://24480205

Differential Revision: http://reviews.llvm.org/D17576

llvm-svn: 261803
This commit is contained in:
Manman Ren 2016-02-24 23:05:43 +00:00
parent 1c576054cb
commit c445d38776
2 changed files with 12 additions and 0 deletions

View File

@ -2110,6 +2110,8 @@ Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl(
Param->setInvalidDecl();
if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) {
EnterExpressionEvaluationContext ConstantEvaluated(SemaRef,
Sema::ConstantEvaluated);
ExprResult Value = SemaRef.SubstExpr(D->getDefaultArgument(), TemplateArgs);
if (!Value.isInvalid())
Param->setDefaultArgument(Value.get());

View File

@ -75,3 +75,13 @@ namespace rdar23810407 {
g<int>();
}
}
// rdar://problem/24480205
namespace PR13986 {
constexpr unsigned Dynamic = 0;
template <unsigned> class A { template <unsigned = Dynamic> void m_fn1(); };
class Test {
~Test() {}
A<1> m_target;
};
}