[llvm-branch-commits] [cfe-branch] r292338 - Merging r292183:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jan 17 20:36:52 PST 2017


Author: hans
Date: Tue Jan 17 22:36:52 2017
New Revision: 292338

URL: http://llvm.org/viewvc/llvm-project?rev=292338&view=rev
Log:
Merging r292183:
------------------------------------------------------------------------
r292183 | rsmith | 2017-01-16 18:14:37 -0800 (Mon, 16 Jan 2017) | 14 lines

Partial revert of r290511.

The rules around typechecking deduced template arguments during partial
ordering are not clear, and while the prior behavior does not seem to be
correct (it doesn't follow the general model of partial ordering where each
template parameter is replaced by a non-dependent but unique value), the new
behavior is also not clearly right and breaks some existing idioms.

The new behavior is retained for dealing with non-type template parameters
with 'auto' types, as without it even the most basic uses of that feature
don't work. We can revisit this once CWG has come to an agreement on how
partial ordering with 'auto' non-type template parameters is supposed to
work.

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

Added:
    cfe/branches/release_40/test/SemaTemplate/partial-order.cpp
      - copied unchanged from r292183, cfe/trunk/test/SemaTemplate/partial-order.cpp
Modified:
    cfe/branches/release_40/   (props changed)
    cfe/branches/release_40/lib/Sema/SemaTemplate.cpp
    cfe/branches/release_40/test/SemaTemplate/class-template-spec.cpp
    cfe/branches/release_40/test/SemaTemplate/temp_arg_nontype.cpp
    cfe/branches/release_40/test/SemaTemplate/temp_arg_template_cxx1z.cpp

Propchange: cfe/branches/release_40/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan 17 22:36:52 2017
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:291850,291853,291865,291871,291877,291879,291881,291907,291964,292032,292052,292265
+/cfe/trunk:291850,291853,291865,291871,291877,291879,291881,291907,291964,292032,292052,292183,292265
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_40/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_40/lib/Sema/SemaTemplate.cpp?rev=292338&r1=292337&r2=292338&view=diff
==============================================================================
--- cfe/branches/release_40/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/branches/release_40/lib/Sema/SemaTemplate.cpp Tue Jan 17 22:36:52 2017
@@ -5127,18 +5127,22 @@ ExprResult Sema::CheckTemplateArgument(N
   if (CTAK == CTAK_Deduced &&
       !Context.hasSameType(ParamType.getNonLValueExprType(Context),
                            Arg->getType())) {
-    // C++ [temp.deduct.type]p17: (DR1770)
-    //   If P has a form that contains <i>, and if the type of i differs from
-    //   the type of the corresponding template parameter of the template named
-    //   by the enclosing simple-template-id, deduction fails.
-    //
-    // Note that CTAK will be CTAK_DeducedFromArrayBound if the form was [i]
-    // rather than <i>.
-    //
-    // FIXME: We interpret the 'i' here as referring to the expression
-    // denoting the non-type template parameter rather than the parameter
-    // itself, and so strip off references before comparing types. It's
-    // not clear how this is supposed to work for references.
+    // FIXME: If either type is dependent, we skip the check. This isn't
+    // correct, since during deduction we're supposed to have replaced each
+    // template parameter with some unique (non-dependent) placeholder.
+    // FIXME: If the argument type contains 'auto', we carry on and fail the
+    // type check in order to force specific types to be more specialized than
+    // 'auto'. It's not clear how partial ordering with 'auto' is supposed to
+    // work.
+    if ((ParamType->isDependentType() || Arg->isTypeDependent()) &&
+        !Arg->getType()->getContainedAutoType()) {
+      Converted = TemplateArgument(Arg);
+      return Arg;
+    }
+    // FIXME: This attempts to implement C++ [temp.deduct.type]p17. Per DR1770,
+    // we should actually be checking the type of the template argument in P,
+    // not the type of the template argument deduced from A, against the
+    // template parameter type.
     Diag(StartLoc, diag::err_deduced_non_type_template_arg_type_mismatch)
       << Arg->getType()
       << ParamType.getUnqualifiedType();

Modified: cfe/branches/release_40/test/SemaTemplate/class-template-spec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_40/test/SemaTemplate/class-template-spec.cpp?rev=292338&r1=292337&r2=292338&view=diff
==============================================================================
--- cfe/branches/release_40/test/SemaTemplate/class-template-spec.cpp (original)
+++ cfe/branches/release_40/test/SemaTemplate/class-template-spec.cpp Tue Jan 17 22:36:52 2017
@@ -207,19 +207,19 @@ namespace NTTPTypeVsPartialOrder {
   struct X { typedef int value_type; };
   template<typename T> struct Y { typedef T value_type; };
 
-  template<typename T, typename T::value_type N> struct A; // expected-note {{template}}
+  template<typename T, typename T::value_type N> struct A;
   template<int N> struct A<X, N> {};
-  template<typename T, T N> struct A<Y<T>, N> {}; // expected-error {{not more specialized}} expected-note {{'T' vs 'typename Y<type-parameter-0-0>::value_type'}}
+  template<typename T, T N> struct A<Y<T>, N> {};
   A<X, 0> ax;
   A<Y<int>, 0> ay;
 
 
-  template<int, typename T, typename T::value_type> struct B; // expected-note {{template}}
-  template<typename T, typename T::value_type N> struct B<0, T, N>; // expected-note {{matches}}
+  template<int, typename T, typename T::value_type> struct B;
+  template<typename T, typename T::value_type N> struct B<0, T, N>;
   template<int N> struct B<0, X, N> {};
-  template<typename T, T N> struct B<0, Y<T>, N> {}; // expected-error {{not more specialized}} expected-note {{'T' vs 'typename Y<type-parameter-0-0>::value_type'}} expected-note {{matches}}
+  template<typename T, T N> struct B<0, Y<T>, N> {};
   B<0, X, 0> bx;
-  B<0, Y<int>, 0> by; // expected-error {{ambiguous}}
+  B<0, Y<int>, 0> by;
 }
 
 namespace DefaultArgVsPartialSpec {

Modified: cfe/branches/release_40/test/SemaTemplate/temp_arg_nontype.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_40/test/SemaTemplate/temp_arg_nontype.cpp?rev=292338&r1=292337&r2=292338&view=diff
==============================================================================
--- cfe/branches/release_40/test/SemaTemplate/temp_arg_nontype.cpp (original)
+++ cfe/branches/release_40/test/SemaTemplate/temp_arg_nontype.cpp Tue Jan 17 22:36:52 2017
@@ -370,13 +370,13 @@ namespace PR17696 {
 }
 
 namespace partial_order_different_types {
-  // These are unordered because the type of the final argument doesn't match.
-  template<int, int, typename T, typename, T> struct A; // expected-note {{here}}
-  template<int N, typename T, typename U, T V> struct A<0, N, T, U, V> {}; // expected-note {{matches}}
-  template<typename T, typename U, U V> struct A<0, 0, T, U, V> {}; // expected-note {{matches}}
-  // expected-error at -1 {{not more specialized than the primary}}
-  // expected-note at -2 {{deduced non-type template argument does not have the same type as the corresponding template parameter ('U' vs 'type-parameter-0-0')}}
-  A<0, 0, int, int, 0> a; // expected-error {{ambiguous partial specializations}}
+  template<int, int, typename T, typename, T> struct A;
+  template<int N, typename T, typename U, T V> struct A<0, N, T, U, V>; // expected-note {{matches}}
+  // FIXME: It appears that this partial specialization should be ill-formed as
+  // it is not more specialized than the primary template. V is not deducible
+  // because it does not have the same type as the corresponding parameter.
+  template<int N, typename T, typename U, U V> struct A<0, N, T, U, V> {}; // expected-note {{matches}}
+  A<0, 0, int, int, 0> a; // expected-error {{ambiguous}}
 }
 
 namespace partial_order_references {
@@ -434,7 +434,7 @@ namespace dependent_nested_partial_speci
 
   template<typename T> struct E {
     template<typename U, U V> struct F; // expected-note {{template}}
-    template<typename W, T V> struct F<W, V> {}; // expected-error {{not more specialized than the primary}} expected-note {{does not have the same type}}
+    template<typename W, T V> struct F<W, V> {}; // expected-error {{not more specialized than the primary}}
   };
   E<int>::F<int, 0> e1; // expected-note {{instantiation of}}
 }

Modified: cfe/branches/release_40/test/SemaTemplate/temp_arg_template_cxx1z.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_40/test/SemaTemplate/temp_arg_template_cxx1z.cpp?rev=292338&r1=292337&r2=292338&view=diff
==============================================================================
--- cfe/branches/release_40/test/SemaTemplate/temp_arg_template_cxx1z.cpp (original)
+++ cfe/branches/release_40/test/SemaTemplate/temp_arg_template_cxx1z.cpp Tue Jan 17 22:36:52 2017
@@ -79,13 +79,13 @@ namespace Auto {
 
   TInt<Auto> ia;
   TInt<AutoPtr> iap; // expected-error {{different template parameters}}
-  TInt<DecltypeAuto> ida; // FIXME expected-error {{different template parameters}}
+  TInt<DecltypeAuto> ida;
   TInt<Int> ii;
   TInt<IntPtr> iip; // expected-error {{different template parameters}}
 
   TIntPtr<Auto> ipa;
   TIntPtr<AutoPtr> ipap;
-  TIntPtr<DecltypeAuto> ipda; // FIXME expected-error {{different template parameters}}
+  TIntPtr<DecltypeAuto> ipda;
   TIntPtr<Int> ipi; // expected-error {{different template parameters}}
   TIntPtr<IntPtr> ipip;
 
@@ -114,6 +114,6 @@ namespace Auto {
 
   int n;
   template<auto A, decltype(A) B = &n> struct SubstFailure;
-  TInt<SubstFailure> isf; // expected-error {{different template parameters}}
-  TIntPtr<SubstFailure> ipsf; // expected-error {{different template parameters}}
+  TInt<SubstFailure> isf; // FIXME: this should be ill-formed
+  TIntPtr<SubstFailure> ipsf;
 }




More information about the llvm-branch-commits mailing list