]> granicus.if.org Git - clang/commitdiff
Fix assertion failure on MaybeODRUseExprs.
authorManman Ren <manman.ren@gmail.com>
Wed, 24 Feb 2016 23:05:43 +0000 (23:05 +0000)
committerManman Ren <manman.ren@gmail.com>
Wed, 24 Feb 2016 23:05:43 +0000 (23:05 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@261803 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateInstantiateDecl.cpp
test/SemaTemplate/default-arguments-cxx0x.cpp

index a76550024ba733db171f4ba92cfc397fe15503f5..829d51ee9688ef97ee283dc13249f91c2294e0bf 100644 (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());
index 0c97c2056b7576052396629a459ec1a720dd4560..c52899a8e6d152a453525112f9053eb9ed6bdb36 100644 (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;
+  };
+}