C++ Logo

std-proposals

Advanced search

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

From: Timur Doumler <cpp_at_[hidden]>
Date: Thu, 4 May 2023 11:26:11 +0200
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.

For things that should indeed be non-ignorable, like const or alignas (keep in mind that alignment requirements can be branched on at compile time), we have keywords (contextual or non-contextual). I don't see a problem with this: keywords for required things, attributes for optional things. So I don't see a need for a new syntax.

Cheers,
Timur

> On 4 May 2023, at 11:17, Oleksandr Koval via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> I'm not convinced with the `no_unique_address` example. As any other attribute, it's optional and doesn't affect the meaning of the program. It sounds like an error to write a code which relies on an observable behavior change caused by any attribute. P1774R8 <https://wg21.link/P1774R8> also discussed a bit about potential observable changes caused by `[[assume]]`.
> With such a feature, should we introduce a set of attributes which can and cannot be required? Like, is it legal to write `[[!nodiscard]]`?
> Maybe there's a space for a similar mechanism in the language but I would not call it "required attributes" because it's just contradictory to the current meaning of attributes.
>
> On Thu, May 4, 2023 at 11:29 AM Bo Persson via Std-Proposals <std-proposals_at_[hidden] <mailto:std-proposals_at_[hidden]>> wrote:
> On 2023-05-04 at 09:47, Lauri Vasama via Std-Proposals wrote:
> > Floating an idea i've been toying around with for a while concerning a
> > new syntax for attributes with observable effects on program behaviour.
> >
> > https://vasama.github.io/wg21/Dxxx1 <https://vasama.github.io/wg21/Dxxx1> <https://vasama.github.io/wg21/Dxxx1 <https://vasama.github.io/wg21/Dxxx1>>
> >
> >
>
> Don't see that an exclamation mark is a good choice for "required", as
> it elsewhere means "not".
>
> Like [[packed]] is optional, but [[!packed]] should be required packing.
> To me it look more like unpacked.
>
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden] <mailto:Std-Proposals_at_[hidden]>
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals <https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals>
>
>
> --
> Regards,
> Oleksandr Koval.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals


Received on 2023-05-04 09:26:18