This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-12-19


2235. Partial ordering and non-dependent types

Section: 13.10.3.5  [temp.deduct.partial]     Status: CD5     Submitter: Richard Smith     Date: 2016-02-25

[Accepted as a DR at the March, 2018 (Jacksonville) meeting.]

Paragraph 12 of 13.10.3.5 [temp.deduct.partial] contains the following example:

  template <class T> T f(int);        // #1
  template <class T, class U> T f(U); // #2
  void g() {
    f<int>(1);                        // calls #1
  }

However, paragraph 4 states,

If a particular P contains no template-parameters that participate in template argument deduction, that P is not used to determine the ordering.

Thus, we ignore the P=int, A=U case and deduction succeeds for the P=U, A=int case, so both templates are at least as specialized as each other. And consider:

  template <class... T> struct V {};
  template <class... Ts, class... Us> void Foo(V<Ts...>, V<Us&...>) {} // #3 
  template <class... Us> void Foo(V<>, V<Us&...>) {}                   // #4 
  void h() {
    Foo(V<>(), V<>());
  }

The intent is that this should call #4; that template clearly ought to be more specialized.

Proposed resolution (November, 2017)

  1. Change 13.10.3.5 [temp.deduct.partial] paragraph 4 as follows:

  2. :
    Each type nominated above from the parameter template and the corresponding type from the argument template are used as the types of P and A. If a particular P contains no template-parameters that participate in template argument deduction, that P is not used to determine the ordering.
  3. Change 13.10.3.6 [temp.deduct.type] paragraph 4 as follows:

  4. ...If a template parameter is used only in non-deduced contexts and is not explicitly specified, template argument deduction fails. [Note: Under 13.10.3.2 [temp.deduct.call] and 13.10.3.5 [temp.deduct.partial], if P contains no template-parameters that appear in deduced contexts, no deduction is done, so P and A need not have the same form. —end note]