https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61961

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #0)
> The semantics I suggest are to warn when:
> 
> * an initializer-list constructor is selected by overload resolution
> * the elements of the braced-init-list are not all the same type
> * another (non-initializer-list) constructor is viable

This would also be useful to warn for the CWG 2137 / PR 76262 / PR 85577 cases
where an initializer-list constructor is chosen for a braced-init-list with a
single element of the same type as the class being constructed. Users almost
always want A{a} to use a copy constructor, and are surprised when GCC chooses
an initializer-list constructor (which other compilers don't do).

So revised suggestion for the semantics:

* an initializer-list constructor is selected by overload resolution
* another (non-initializer-list) constructor is viable
* either the braced-init-list has more than one element and they are not all
the same type, or it has exactly one element and its type is the same as the
class being constructed.

I think this should be included in -Wall. If the initializer-list constructor
is really intended then the warning can be suppressed by explicitly converting
the initializers to the intended type, which more clearly expresses the
intended meaning of the code anyway.

Reply via email to