Here, we're rejecting the specialization of g<T,F> with T=A, F=&f in the first testcase due to a spurious constness mismatch between the type of the template argument &f and the substituted type of F (the substituted type has a top-level const). Note that this mismatch doesn't occur with object pointers because in that case a call to perform_qualification_conversions from convert_nontype_argument implicitly adds a top-level const to the argument (via a cast) to match.
This however seems to be a manifestation of a more general conformance issue -- that we're not dropping top-level cv-quals after substituting into the type of an NTTP as per [temp.param]/6 (we only do so at parse time in process_template_parm). This patch makes convert_template_argument drop top-level cv-quals accordingly. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? PR c++/100893 gcc/cp/ChangeLog: * pt.c (convert_template_argument): Strip top-level cv-quals on the substituted type of a non-type template parameter. gcc/testsuite/ChangeLog: * g++.dg/template/param4.C: New test. * g++.dg/template/param5.C: New test. --- gcc/cp/pt.c | 7 ++++++- gcc/testsuite/g++.dg/template/param4.C | 10 ++++++++++ gcc/testsuite/g++.dg/template/param5.C | 7 +++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/template/param4.C create mode 100644 gcc/testsuite/g++.dg/template/param5.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 7211bdc5bbc..66cc88a331f 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -8494,7 +8494,12 @@ convert_template_argument (tree parm, return error_mark_node; } else - t = tsubst (t, args, complain, in_decl); + { + t = tsubst (t, args, complain, in_decl); + /* Ignore top-level qualifiers on the substituted type of this + non-type template parameter, as per [temp.param]/6. */ + t = cv_unqualified (t); + } if (invalid_nontype_parm_type_p (t, complain)) return error_mark_node; diff --git a/gcc/testsuite/g++.dg/template/param4.C b/gcc/testsuite/g++.dg/template/param4.C new file mode 100644 index 00000000000..d55fecec2d9 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/param4.C @@ -0,0 +1,10 @@ +// PR c++/100893 + +template<class T, typename T::type F> void g() { } + +struct A { typedef void (* const type)(); }; +void f(); +template void g<A, &f>(); + +struct B { typedef void (B::* const type)(); void f(); }; +template void g<B, &B::f>(); diff --git a/gcc/testsuite/g++.dg/template/param5.C b/gcc/testsuite/g++.dg/template/param5.C new file mode 100644 index 00000000000..b8c92f4c217 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/param5.C @@ -0,0 +1,7 @@ +// Verify top-level cv-qualifiers are dropped when determining the substituted +// type of a non-type-template parameter, as per [temp.param]/6. +// { dg-do compile { target c++11 } } + +template<class T, T V> decltype(V)& f(); +using type = decltype(f<const volatile int, 0>()); +using type = int&; -- 2.32.0.rc2