C++ Logo


Advanced search

Re: Constructor ambiguity: Uniform initialization vs. initializer lists

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Tue, 5 Oct 2021 10:03:25 -0400
On Tue, Oct 5, 2021 at 8:12 AM Gawain Bolton via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> Hello,
> I would like to report what I will call "constructor ambiguity" for classes which have multiple constructors, one of which have takes an initializer list.
> The ambiguity is for us humans, not the compiler, and is due to the two things:
> The same syntax is used for uniform initialization and initializer lists.
> Any constructor taking an initializer list is preferred when braces are used.

This has been talked about a lot. And there's nothing that can be done
to change it, as any change would break tons and tons of existing
code. This is a mistake that was made a decade ago, and there's little
that can be done save living with its consequences.

The only potential fix possible would be to make an alteration of the
list initialization syntax that allows you to specify whether you want
the list to call a normal constructor/aggregate-initialization or
whether you want to use an initializer-list constructor (my idea would
be `{c: ...}` for constructor, and `{l: ...}` for initializer list).
But I highly suspect nobody would be interested in such a thing.

Received on 2021-10-05 09:05:50