Created on 2011-04-30.00:00:00 last changed 121 months ago
[Moved to DR at the September, 2013 meeting.]
Proposed resolution, April, 2013:
Change 12.2.4.2.6 [over.ics.list] paragraph 2 as follows, adding a new paragraph (and moving the footnote to the new paragraph, as indicated):
[Drafting note: no other case in the remainder of the paragraph applies when the initializer list has more elements than the parameter array.]If the parameter type is std::initializer_list<X>
or “array of X” [Footnote: Since there are no parameters of array type, this will only occur as the underlying type of a reference parameter. —end footnote]and all the elements of the initializer list can be implicitly converted to X, the implicit conversion sequence is the worst conversion necessary to convert an element of the list to X. This conversion can be a user-defined conversion even in the context of a call to an initializer-list constructor. [Example: ... —end example]Otherwise, if the parameter type is “array of N X” [Footnote: Since there are no parameters of array type, this will only occur as the underlying type of a reference parameter. —end footnote], if the initializer list has exactly N elements or if it has fewer than N elements and X is default-constructible, and if all the elements of the initializer list can be implicitly converted to X, the implicit conversion sequence is the worst conversion necessary to convert an element of the list to X.
Change 12.2.4.3 [over.ics.rank] paragraph 3 as follows:
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 than list-initialization sequence L2 if
L1 converts to std::initializer_list<X> for some X and L2 does not.
L1 converts to std::initializer_list<X> for some X and L2 does not, or, if not that,
L1 converts to type “array of N1 T,” L2 converts to type “array of N2 T”, and N1 is smaller than N2.
Notes from the October, 2012 meeting:
CWG determined that this issue is unrelated to array temporaries and that a tiebreaker should be added for this case in overload resolution.
In an example like
void f(int const(&)[2]); void f(int const(&)[3]); int main() { f({1, 2, 3}); }
the current overload resolution rules make no provision for different array sizes and thus treats the call as ambiguous, even though it seems obvious that the second f should be chosen in this case.
History | |||
---|---|---|---|
Date | User | Action | Args |
2014-11-24 00:00:00 | admin | set | status: drwp -> c++14 |
2014-03-03 00:00:00 | admin | set | status: dr -> drwp |
2013-10-14 00:00:00 | admin | set | messages: + msg4698 |
2013-10-14 00:00:00 | admin | set | status: ready -> dr |
2013-05-03 00:00:00 | admin | set | messages: + msg4315 |
2013-05-03 00:00:00 | admin | set | status: drafting -> ready |
2012-11-03 00:00:00 | admin | set | messages: + msg4102 |
2012-11-03 00:00:00 | admin | set | status: extension -> drafting |
2012-09-24 00:00:00 | admin | set | messages: + msg4039 |
2011-04-30 00:00:00 | admin | create |