Array reference vs array decay in overload resolution
Section [over.ics.rank]
Faisal Vali

Created on 2013-10-01.00:00:00 last changed 1 month ago


Date: 2023-02-07.05:24:22

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);
Date: 2021-06-15.00:00:00

Proposed resolution (June, 2021):

Add the following as a new bullet following [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:

  • List-initialization sequence L1 is a better conversion sequence...

  • Standard conversion sequence S1 is a better conversion sequence than standard conversion sequence S2 if

    • ...

    • S1 and S2 include reference bindings (9.4.4 [dcl.init.ref]), and the types to which the references refer are the same type except for top-level cv-qualifiers, and the type to which the reference initialized by S2 refers is more cv-qualified than the type to which the reference initialized by S1 refers. [Example 6:...

    • S1 is a reference binding to an array and S2 is an array-to-pointer conversion (7.3.3 [conv.array]). [Example 7:

        template<class T, unsigned N> void f(T (&)[N]); // #1
        template<class T> void f(T *t);                 // #2
        int r[3]{1, 2, 3};
        void g() {
          f(r);    // OK: calls #1

      end example]

Date: 2013-10-01.00:00:00

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};

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

Date User Action Args
2023-02-07 05:24:22adminsetmessages: + msg7161
2023-02-07 05:24:22adminsetstatus: tentatively ready -> open
2022-11-20 07:54:16adminsetstatus: review -> tentatively ready
2021-11-15 00:00:00adminsetmessages: + msg6531
2021-11-15 00:00:00adminsetstatus: drafting -> review
2014-03-03 00:00:00adminsetstatus: open -> drafting
2013-10-01 00:00:00admincreate