determine_specialization hadn't been taught about ref-qualifiers yet. Tested x86_64-pc-linux-gnu, applying to trunk/7/6.
commit f69972ff3fa2b33609e1952c0936f13e98161e5f Author: Jason Merrill <ja...@redhat.com> Date: Wed Feb 28 15:17:08 2018 -0500
PR c++/71784 - ICE with ref-qualifier and explicit specialization. * pt.c (determine_specialization): Check ref-qualifier. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 23eb2db1a5d..e17b5387514 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -2164,10 +2164,17 @@ determine_specialization (tree template_id, that the const qualification is the same. Since get_bindings does not try to merge the "this" parameter, we must do the comparison explicitly. */ - if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn) - && !same_type_p (TREE_VALUE (fn_arg_types), - TREE_VALUE (decl_arg_types))) - continue; + if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)) + { + if (!same_type_p (TREE_VALUE (fn_arg_types), + TREE_VALUE (decl_arg_types))) + continue; + + /* And the ref-qualification. */ + if (type_memfn_rqual (TREE_TYPE (decl)) + != type_memfn_rqual (TREE_TYPE (fn))) + continue; + } /* Skip the "this" parameter and, for constructors of classes with virtual bases, the VTT parameter. A @@ -2278,6 +2285,11 @@ determine_specialization (tree template_id, decl_arg_types)) continue; + if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn) + && (type_memfn_rqual (TREE_TYPE (decl)) + != type_memfn_rqual (TREE_TYPE (fn)))) + continue; + // If the deduced arguments do not satisfy the constraints, // this is not a candidate. if (flag_concepts && !constraints_satisfied_p (fn)) diff --git a/gcc/testsuite/g++.dg/cpp0x/ref-qual18.C b/gcc/testsuite/g++.dg/cpp0x/ref-qual18.C new file mode 100644 index 00000000000..aaa00b9cfc3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/ref-qual18.C @@ -0,0 +1,18 @@ +// PR c++/71784 +// { dg-do compile { target c++11 } } + +template<typename T> struct A { + template<typename U> void f(U const&) & { } + template<typename U> void f(U const&) && { } +}; + +template void A<int>::f<int>(int const&) &; +template void A<float>::f<int>(int const&) &&; + +template<typename T> struct B { + void f(int const&) & { } + void f(int const&) && { } +}; + +template void B<int>::f(int const&) &; +template void B<float>::f(int const&) &&;