Created on 2013-10-01.00:00:00 last changed 21 months ago
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);
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:
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]
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?
History | |||
---|---|---|---|
Date | User | Action | Args |
2023-02-07 05:24:22 | admin | set | messages: + msg7161 |
2023-02-07 05:24:22 | admin | set | status: tentatively ready -> open |
2022-11-20 07:54:16 | admin | set | status: review -> tentatively ready |
2021-11-15 00:00:00 | admin | set | messages: + msg6531 |
2021-11-15 00:00:00 | admin | set | status: drafting -> review |
2014-03-03 00:00:00 | admin | set | status: open -> drafting |
2013-10-01 00:00:00 | admin | create |