C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Declare as constinit, define as constexpr?

From: Thiago Macieira <thiago_at_[hidden]>
Date: Tue, 12 Dec 2023 16:48:50 -0300
On Tuesday, 12 December 2023 16:37:50 -03 Ville Voutilainen wrote:
> > If you want this to change, it needs to be a paper.
>
> Sure. Just another lil' addition: quite like we can already write
>
> extern const int x;
>
> constexpr int x = 42;

constexpr are implicitly inline, so these two don't actually work
independently. At a minimum you must ensure that the former is visible before
the latter. Or write extern constexpr.

> it seems eminently reasonable to be able to write
>
> extern constinit const int x;
>
> constexpr int x = 42;

What's the point of an extern constinit without the initialisation? One does
not need to know how to initialise this variable to use it. And without the
initialiser, how would the constinit keyword make any difference in this line?

So, is this different from the case above?

> The "we can already write" bit convinces me that we should just do
> this. But yes, agreed, as I said, a paper,
> please, not an issue submission. Core would need to punt the issue to
> Evolution to be handled as an extension
> anyway, so better just write a paper and send it to Evolution.


-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-12-12 19:48:55