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

2024-04-18


1789. Array reference vs array decay in overload resolution

Section: 12.2.4.3  [over.ics.rank]     Status: open     Submitter: Faisal Vali     Date: 2013-10-01

The current rules make an example like

  template<class T, size_t N> void foo(T (&)[N]);
  template<class T> void foo(T *t);

  int arr[3]{1, 2, 3};
  foo(arr);

ambiguous, even though the first is an identity match and the second requires an lvalue transformation. Is this desirable?

Proposed resolution (June, 2021):

Add the following as a new bullet following 12.2.4.3 [over.ics.rank] bullet 3.2.6:

Two implicit conversion sequences of the same form are indistinguishable conversion sequences unless one of the following rules applies:

CWG 2023-02-06

The proposed resolution prefers the T& overload over the T* overload in the example below, which is undesirable. The wording needs to be amended to limit the tiebreaker to situations where the array declarator appears in the signature.

template<class T>
int f(T&);
template<class T>
int f(T*);
int x[5];
int z = f(x);