C++ Logo


Advanced search

Re: [SG20] [isocpp-ext] "constinit" seems to be very confusing

From: Gabriel Dos Reis <gdr_at_[hidden]>
Date: Mon, 23 Nov 2020 05:09:38 +0000
> A C++17 implementation would parse and ignore the attribute, producing an incorrect program.

Ville is correct that changing a static initialization to dynamic initialization (without other program transformation) can introduce hard-to-track-down bugs, i.e. expensive bugs. That has happened in actual life, leading the Windows codebase profusely and enthusiastically embracing constexpr on local 'static' local variables.

-- Gaby

-----Original Message-----
From: Ext <ext-bounces_at_[hidden]> On Behalf Of Ville Voutilainen via Ext
Sent: Sunday, November 22, 2020 9:04 PM
To: sg20_at_[hidden]
Cc: Ville Voutilainen <ville.voutilainen_at_[hidden]>; Evolution Working Group mailing list <ext_at_[hidden]>
Subject: Re: [isocpp-ext] [SG20] "constinit" seems to be very confusing

On Mon, 23 Nov 2020 at 04:01, Arthur O'Dwyer via SG20 <sg20_at_[hidden]> wrote:
> `constinit` is simple and regular:
> constinit int x = foo();
> means no more and no less than
> int x = foo();
> with the additional information that the initialization must happen at
> compile-time, not at runtime. In a perfect world, it would have been
> an attribute, since it has no effect on the type system. (But we're
> hung up on the ignorable attributes rule.)

It's not a question of being hung up on a rule. A C++17 implementation would parse and ignore the attribute, producing an incorrect program. It's a keyword in order to make sure that it's not ignored by an implementation that doesn't recognize it, and that's not a result of being "hung up", it's a result of what the language was before
C++20, and changing that is not something that we could just do with a
DR, because implementations have already shipped.

But hey, if your "perfect world" includes having to do a language version (and possibly an implementation version, because surreptitious(*) bugs) check whenever using a language facility, then by all means, propose such a perfect world. Otherwise, I recommend communicating the reasons for choosing a keyword rather than an attribute correctly. C++ has enough teaching material that has such correctness problems, and I doubt whether that's exactly productive.

(*) bugs in different meanings of (unrecognized) attributes are already surreptitious, based on what we've seen in the wild; a bug in recognizing a new keyword is unlikely to be surreptitious, based on how most of our parsers work.
Ext mailing list
Subscription: https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.isocpp.org%2Fmailman%2Flistinfo.cgi%2Fext&amp;data=04%7C01%7Cgdr%40microsoft.com%7Cf964e01c658345d4bd0808d88f6d43be%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637417046748962964%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=QkuADgD9rgj8TMS3qCKA8jT52dQ6xzWp1N8kx%2FkMc5Q%3D&amp;reserved=0
Link to this post: https://nam06.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.isocpp.org%2Fext%2F2020%2F11%2F15310.php&amp;data=04%7C01%7Cgdr%40microsoft.com%7Cf964e01c658345d4bd0808d88f6d43be%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637417046748962964%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=M3P0dTn%2BqA0SlU4VpYMZ0vj8yudO1MhbE2uOFjTWWYs%3D&amp;reserved=0

Received on 2020-11-22 23:09:41