Date: Fri, 27 Jun 2025 00:45:55 +0200
Hi,
Motivation:
Currently for class T following declarations have different initialization
rules depending on whether some constructors are declared explicit or not.
T a{b}; // 1
T a = {b}; // 2
T a = b; // 3
But since C++17 guaranteed copy-ellision this divergence doesn't really
make sense. In all scenarios the initialized object is always of type T,
and we are explicit about it because we provide the type in the declaration.
So there is no possibility of unintended conversion that 'explicit' keyword
is supposed to protect from.
My proposal is:
- in C++29 add a warning for scenarios 2) and 3) if they would select a
different constructor than 1),
- in C++32 make 2) and 3) behave exactly the same as 1).
Regards,
Maciej Cencora
Motivation:
Currently for class T following declarations have different initialization
rules depending on whether some constructors are declared explicit or not.
T a{b}; // 1
T a = {b}; // 2
T a = b; // 3
But since C++17 guaranteed copy-ellision this divergence doesn't really
make sense. In all scenarios the initialized object is always of type T,
and we are explicit about it because we provide the type in the declaration.
So there is no possibility of unintended conversion that 'explicit' keyword
is supposed to protect from.
My proposal is:
- in C++29 add a warning for scenarios 2) and 3) if they would select a
different constructor than 1),
- in C++32 make 2) and 3) behave exactly the same as 1).
Regards,
Maciej Cencora
Received on 2025-06-26 22:46:12