C++ Logo


Advanced search

Re: Fixing some initialization gotchas

From: Barry Revzin <barry.revzin_at_[hidden]>
Date: Fri, 23 Aug 2019 08:32:50 -0600
On Fri, Aug 23, 2019, 8:21 AM Maciej Cencora via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Yes, I am proposing to make 'auto x{1};' ill formed because such form is
> ambiguous depending on how many elements you pass in braced init list (and
> it differs in C++11).
> Fixing the fall-out is trivial (either use 'auto x = 1;' or
> 'std::initializer_list x = { 1 };') and compatible with C++17.
> Isn't simplification of initialization rules a good enough argument?
> Aah, I forgot to write, I propose to unify direct-init and copy-init as
> well:
> T a = b;
> T a(b);
> In C++17 these will do exactly the same thing (minus explicit constructor).

Yeah, but "minus explicit constructor" is kind of significant. What you're
proposing is effectively to get rid of the explicit keyword.

The argument you have to make is that explicit adds no value. I, for one,
like that neither

vector<string> names() { return 3; }


void timeout(std::chrono::seconds)

compile today.



Received on 2019-08-23 09:35:05