[llvm-branch-commits] [cfe-branch] r258549 - Merging r258110:

Dimitry Andric via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Jan 22 12:43:39 PST 2016


Author: dim
Date: Fri Jan 22 14:43:39 2016
New Revision: 258549

URL: http://llvm.org/viewvc/llvm-project?rev=258549&view=rev
Log:
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!





------------------------------------------------------------------------

Modified:
    cfe/branches/release_38/   (props changed)
    cfe/branches/release_38/lib/Sema/SemaTemplate.cpp
    cfe/branches/release_38/test/SemaTemplate/default-arguments.cpp

Propchange: cfe/branches/release_38/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jan 22 14:43:39 2016
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:257652,257695
+/cfe/trunk:257652,257695,258110
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_38/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_38/lib/Sema/SemaTemplate.cpp?rev=258549&r1=258548&r2=258549&view=diff
==============================================================================
--- cfe/branches/release_38/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/branches/release_38/lib/Sema/SemaTemplate.cpp Fri Jan 22 14:43:39 2016
@@ -3281,7 +3281,6 @@ SubstDefaultTemplateArgument(Sema &SemaR
   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);

Modified: cfe/branches/release_38/test/SemaTemplate/default-arguments.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_38/test/SemaTemplate/default-arguments.cpp?rev=258549&r1=258548&r2=258549&view=diff
==============================================================================
--- cfe/branches/release_38/test/SemaTemplate/default-arguments.cpp (original)
+++ cfe/branches/release_38/test/SemaTemplate/default-arguments.cpp Fri Jan 22 14:43:39 2016
@@ -179,3 +179,31 @@ struct C {
   C(T t = ); // expected-error {{expected expression}}
 };
 C<int> obj;
+
+namespace PR26134 {
+// Make sure when substituting default template arguments we do it in the current context.
+template<class T, bool Val = T::value>
+struct X {};
+
+template<bool B> struct Y {
+  void f() { X<Y> xy; }
+  static const bool value = B;
+};
+
+namespace ns1 {
+template<class T0>
+struct X {
+  template<bool B = T0::value> struct XInner { static const bool value = B; };
+};
+template<bool B> struct S { static const bool value = B; };
+#if __cplusplus > 199711L
+template<bool B> struct Y {
+  static constexpr bool f() { return typename X<S<B>>::template XInner<>{}.value; }
+  static_assert(f() == B, "");
+};
+Y<true> y;
+Y<false> y2;
+#endif
+
+} // end ns1
+} // end ns PR26134




More information about the llvm-branch-commits mailing list