C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Unifying initialization rules for variable declarations

From: Andre Kostur <andre_at_[hidden]>
Date: Thu, 26 Jun 2025 20:17:26 -0700
You don’t need to wait for 29 to emit warnings: just convince the compiler
vendors that it is worth it, and they can add whatever warnings they desire.

As for dropping it: that is likely difficult as there is likely code out
there that depends on the current behaviour, and this could break that code.

On Thu, Jun 26, 2025 at 15:46 Maciej Cencora via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> 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
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2025-06-27 03:17:43