Title
Conversions in template argument deduction
Status
nad
Section
13.10.2 [temp.arg.explicit]
Submitter
Vinny Romano

Created on 2015-11-14.00:00:00 last changed 74 months ago

Messages

Date: 2016-11-15.00:00:00

Rationale (November, 2016):

Although there is an argument to be made for the suggested direction, the current rule is simple and easy to explain, so there was no consensus for a change.

Date: 2022-11-20.07:54:16

Consider:

  struct S
  {
   operator int();
  };

  template<int N>
  void f(const int (&)[N]);

  int main()
  {
   S s;
   f<2>({s, s}); // #1
   f({s, s});  // #2
  }

Since the array element type is not deduced, implicit conversions ought to be permitted in #2 but other implementations disagree. Is there a compelling reason to disallow them?

For comparison:

  #include <initializer_list>

  struct S
  {
   operator int();
  };

  template<typename T>
  void f(std::initializer_list<T>);

  int main()
  {
   S s;
   f<int>({s, s});
  }

Because T is not deduced, implicit conversions are allowed, and the number of elements in the underlying temporary array is determined from the number of elements in the initializer list. It seems that the intention of issue 1591 was to allow the underlying temporary array to be deduced directly, so the fact that the array bounds are deduced in the case above shouldn't inhibit implicit conversions.

History
Date User Action Args
2018-02-27 00:00:00adminsetmessages: + msg6021
2018-02-27 00:00:00adminsetstatus: open -> nad
2015-11-14 00:00:00admincreate