C++ Logo


Advanced search

Re: [wg14/wg21 liaison] P2961R1 syntax for Contracts: viable for C?

From: Jens Maurer <jens.maurer_at_[hidden]>
Date: Fri, 6 Oct 2023 16:44:03 +0200
On 06/10/2023 15.58, Timur Doumler via Liaison wrote:
> Thanks Aaron,
>> On 6 Oct 2023, at 16:53, Aaron Ballman <aaron_at_[hidden]> wrote:
>> C23 Footnote 186: Standard attributes specified by this document can
>> be parsed but ignored by an implementation without changing the
>> semantics of a correct program; the same is not true for attributes
>> not specified by this document.
> Interesting. It seems a bit ambiguous to me what "parsed but ignored" actually means. If we go with the P2935 (attribute-like) syntax for Contracts and you end up having something like this:
> [[ assert: x != 0 ]];
> Does "parse" mean that you have to actually parse `x != 0` as an expression, since the grammar for contracts says that the thing after the colon is an expression? Or does "when you see `[[`, skip every token until you reach the matching `]]` " also count as "parse"?

Since C doesn't have attributes with expressions (yet),
a rephrasing of the question is:

In the following example:

[[nodiscard('a')]] bool f();

Is a conforming implementation of C required to diagnose the
bad argument for the "nodiscard" attribute?

My understanding is that the "... is ignored" in the quoted section
C23 6.7.12p2 means "a conforming implementation is not required to
diagnose the above translation unit".


Received on 2023-10-06 14:44:07