C++ Logo


Advanced search

Re: [std-proposals] [Draft Proposal] Required attribute syntax

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Thu, 4 May 2023 10:50:25 +0100
On Thu, 4 May 2023 at 10:26, Timur Doumler via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Attributes are for ignorable things. I proposed to add an explicit
> Ignorability Rule to the standard – which we did for C++23:
> Now, no_unique_address is a class layout hint. It is to composition what
> the Empty Base Optimisation is to inheritance. The EBO is likewise not a
> required optimisation, only an optional one (the only difference being that
> it doesn't have its own annotation). More generally, the standard doesn't
> require any particular class layout in any particular scenario. Your code
> should not portably rely on a particular class layout. Considering that,
> I'm not sure it makes sense to have a non-ignorable no_unique_address.

And if you really do require a particular layout when using
[[no_unique_address]], knowing that doing so is not portable, then you can
use a static_assert to ensure that you get that layout.

"The non-required forms of any existing standard attributes with effects on
program behaviour, such as no_unique_address, should also be deprecated" --
that would be a serious breaking change for questionable benefit.

w.r.t your proposed wording, you've introduced a new grammar but haven't
said what it means. A term should be in italics when it's defined, not when
it's used. You're using the new term "required attribute"in italics, but
you never define it anywhere. Presumably you wanted to say that when the !
is present in an attribute, it's a required attribute, but you haven't
actually said that.

Received on 2023-05-04 09:50:40