C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Expanding constinit

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Fri, 26 Jan 2024 12:59:04 +0300
On 1/26/24 12:42, Franklin Yang via Std-Proposals wrote:
> Hello all,
>
> Currently, constinit can only apply to static or thread storage
> duration. I propose it should also be applicable to automatic storage
> duration.
>
> Furthermore, const member variables of constinit objects will be
> constant expressions (which would also make getter functions of these
> members constant).
>
> These changes should be beneficial in ensuring that construction has no
> runtime overhead, and could potentially also open up new possibilities
> with non-static constexpr fields.
>
> Any thoughts?

Initializing a variable on the stack always has overhead because the
stack memory is generally initialized with garbage. Since constinit
basically means exactly *zero* initialization code in runtime, I don't
see how it would work for variables in the stack.

Received on 2024-01-26 09:59:08