Title
Preferring an initializer_list over a single value
Status
open
Section
12.2.4.3 [over.ics.rank]
Submitter
Jason Merrill

Created on 2022-12-10.00:00:00 last changed 16 months ago

Messages

Date: 2022-12-10.00:00:00

Consider:

  #include <initializer_list>
  struct A { A(int) {} };
  void f(int) = delete;
  void f(std::initializer_list<A>) {}   // #1
  int main() { f({10}); }

The intent of issue 1467 was to make this example well-formed by choosing #1, according to this rule and a corresponding example in 12.2.4.3 [over.ics.rank] bullet 3.1:

  • 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, or, if not that,
    • ...
    even if one of the other rules in this paragraph would otherwise apply.
  • ...

See also issue 2137 and gcc issue 64665.

Possible resolution:

Move 12.2.4.3 [over.ics.rank] paragraph 2 into paragraph 3 as follows:

When comparing the basic forms of implicit conversion sequences (as defined in 12.2.4.2 [over.best.ics])

  • a standard conversion sequence (12.2.4.2.2 [over.ics.scs]) is a better conversion sequence than a user-defined conversion sequence or an ellipsis conversion sequence, and
  • a user-defined conversion sequence (12.2.4.2.3 [over.ics.user]) is a better conversion sequence than an ellipsis conversion sequence (12.2.4.2.4 [over.ics.ellipsis]).

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, or, if not that,
    • ...
    even if one of the other rules in this paragraph would otherwise apply.
  • Otherwise, a standard conversion sequence (12.2.4.2.2 [over.ics.scs]) is a better conversion sequence than a user-defined conversion sequence or an ellipsis conversion sequence, and
  • a user-defined conversion sequence (12.2.4.2.3 [over.ics.user]) is a better conversion sequence than an ellipsis conversion sequence (12.2.4.2.4 [over.ics.ellipsis]).
  • Standard conversion sequence S1 is a better conversion sequence than ...

History
Date User Action Args
2022-12-10 00:00:00admincreate