The resolution of Core DRs 1391 and 1847 clarified that function
parameters that don't involve deducible template parameters are not
considered for partial ordering.  I also experimented with handling
this at a finer-grained level, in unify, so that we would handle a
typename vs. a concrete type even if there were other deducible
template parameters, but that broke template/partial15.C.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 8e4f455347781e161b73a121038efd76dc376aaa
Author: Jason Merrill <ja...@redhat.com>
Date:   Wed Mar 1 16:56:20 2017 -1000

            CWG 1847 - Clarifying compatibility during partial ordering
    
            * pt.c (more_specialized_fn): No order between two non-deducible
            parameters.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index b9e7af7..17398c9 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -21182,6 +21182,13 @@ more_specialized_fn (tree pat1, tree pat2, int len)
           len = 0;
         }
 
+      /* DR 1847: If a particular P contains no template-parameters that
+        participate in template argument deduction, that P is not used to
+        determine the ordering.  */
+      if (!uses_deducible_template_parms (arg1)
+         && !uses_deducible_template_parms (arg2))
+       goto next;
+
       if (TREE_CODE (arg1) == REFERENCE_TYPE)
        {
          ref1 = TYPE_REF_IS_RVALUE (arg1) + 1;
@@ -21303,6 +21310,8 @@ more_specialized_fn (tree pat1, tree pat2, int len)
           These must be unordered.  */
        break;
 
+    next:
+
       if (TREE_CODE (arg1) == TYPE_PACK_EXPANSION
           || TREE_CODE (arg2) == TYPE_PACK_EXPANSION)
         /* We have already processed all of the arguments in our
diff --git a/gcc/testsuite/g++.dg/template/partial-order1.C 
b/gcc/testsuite/g++.dg/template/partial-order1.C
new file mode 100644
index 0000000..0832ea5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/partial-order1.C
@@ -0,0 +1,18 @@
+// { dg-do compile { target c++11 } }
+
+using size_t = decltype(sizeof(0));
+template <class T> struct A
+{
+  using size_type = size_t;
+};
+
+template <class T>
+void f(size_t, T);
+
+template <class T>
+void f(typename A<T>::size_type, T);
+
+int main()
+{
+  f(1,2);                      // { dg-error "ambiguous" }
+}

Reply via email to