C++ Logo

STD-PROPOSALS

Advanced search

Subject: [std-proposals] Fixing some initialization gotchas
From: Maciej Cencora (m.cencora_at_[hidden])
Date: 2019-08-22 15:01:00


Hi,

with C++17 guaranteed copy initialization, the distinction between direct
list initialization and copy list initialization has become illusory.

When we initialize a variable with both of these syntaxes:
1) T a{ param };
2) T a = { param };

We always create a variable of known type, so there is no point in making
these syntaxes behave differently (currently the only known difference to
me is the explicit constructor).

So first proposal is merging direct and copy list initialization into one.

Second idea is fixing the ambiguities with auto construction.
auto a{1}; // a is of type int
auto a = { 1 }; // a is std::initializer_list<int>

I propose to acknowledge the truth, these are ambiguous, let's just make
list initialization of auto ill formed.

This will force users to use following unambiguous syntaxes:
auto a = 1;
or
std::initializer_list a = { 1 };

Regards,
Maciej



STD-PROPOSALS list run by herb.sutter at gmail.com

Standard Proposals Archives on Google Groups