From: Dimitry Andric Date: Fri, 22 Jan 2016 20:43:39 +0000 (+0000) Subject: Merging r258110: X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1dc0d8b09cefcb0b354f0fbde009c722cf44207c;p=clang Merging r258110: ------------------------------------------------------------------------ r258110 | faisalv | 2016-01-19 04:58:55 +0100 (Tue, 19 Jan 2016) | 15 lines Fix PR26134: When substituting into default template arguments, keep CurContext unchanged. Or, do not set Sema's CurContext to the template declaration's when substituting into default template arguments of said template declaration. If we do push the template declaration context on to Sema, and the template declaration is at namespace scope, Sema can get confused and try and do odr analysis when substituting into default template arguments, even though the substitution could be occurring within a dependent context. I'm not sure why this was being done, perhaps there was concern that if a default template argument referred to a previous template parameter, it might not be found during substitution - but all regression tests pass, and I can't craft a test that would cause it to fails (if some one does, please inform me, and i'll craft a different fix for the PR). This patch removes a single line of code, but unfortunately adds more than it removes, because of the tests. Some day I still hope to commit a patch that removes far more lines than it adds, while leaving clang better for it ;) Sorry that r253590 ("Change the expression evaluation context from Unevaluated to ConstantEvaluated while substituting into non-type template argument defaults") caused the PR! ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_38@258549 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 57156078c8..138cee0b94 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -3281,7 +3281,6 @@ SubstDefaultTemplateArgument(Sema &SemaRef, for (unsigned i = 0, e = Param->getDepth(); i != e; ++i) TemplateArgLists.addOuterTemplateArguments(None); - Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext()); EnterExpressionEvaluationContext ConstantEvaluated(SemaRef, Sema::ConstantEvaluated); return SemaRef.SubstExpr(Param->getDefaultArgument(), TemplateArgLists); diff --git a/test/SemaTemplate/default-arguments.cpp b/test/SemaTemplate/default-arguments.cpp index 740a5a9d07..d3e249db7e 100644 --- a/test/SemaTemplate/default-arguments.cpp +++ b/test/SemaTemplate/default-arguments.cpp @@ -179,3 +179,31 @@ struct C { C(T t = ); // expected-error {{expected expression}} }; C obj; + +namespace PR26134 { +// Make sure when substituting default template arguments we do it in the current context. +template +struct X {}; + +template struct Y { + void f() { X xy; } + static const bool value = B; +}; + +namespace ns1 { +template +struct X { + template struct XInner { static const bool value = B; }; +}; +template struct S { static const bool value = B; }; +#if __cplusplus > 199711L +template struct Y { + static constexpr bool f() { return typename X>::template XInner<>{}.value; } + static_assert(f() == B, ""); +}; +Y y; +Y y2; +#endif + +} // end ns1 +} // end ns PR26134