Title
Narrowing conversions and overload resolution
Status
open
Section
12.2.4.2.6 [over.ics.list]
Submitter
David Krauss

Created on 2015-08-26.00:00:00 last changed 7 months ago

Messages

Date: 2016-03-15.00:00:00

Rationale (March, 2016):

This is a question of language design and thus more suited to consideration by EWG.

EWG (January, 2021):

Adjust the standard to follow existing implementations. See vote.

Date: 2022-11-20.07:54:16

Current implementations ignore narrowing conversions during overload resolution, emitting a diagnostic if calling the selected function would involve narrowing. For example:

  struct s { long m };
  struct ss { short m; };

  void f( ss );
  void f( s );
  void g() {
    f({ 1000000 }); // Ambiguous in spite of narrowing for f(ss)
  }

However, the current wording of 12.2.4.2.6 [over.ics.list] paragraph 7 says,

Otherwise, if the parameter has an aggregate type which can be initialized from the initializer list according to the rules for aggregate initialization (9.4.2 [dcl.init.aggr]), the implicit conversion sequence is a user-defined conversion sequence with the second standard conversion sequence an identity conversion.

In the example above, ss cannot be initialized from { 1000000 } because of the narrowing conversion, so presumably f(ss) should not be considered. If this is not the intended outcome, paragraph 7 should be restated in terms of having an implicit conversion sequence, as in, e.g., bullet 9.1, instead of a valid initialization.

History
Date User Action Args
2022-04-27 22:23:07adminsetstatus: extension -> open
2017-02-06 00:00:00adminsetmessages: + msg5998
2017-02-06 00:00:00adminsetstatus: open -> extension
2016-02-15 00:00:00adminsetstatus: drafting -> open
2015-08-26 00:00:00admincreate