C++ Logo

liaison

Advanced search

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

From: Timur Doumler <cpp_at_[hidden]>
Date: Fri, 6 Oct 2023 19:23:04 +0300
Thanks for the explanation, Aaron!

If this is indeed how attribute ignorability works in C (a compiler is allowed to just skip all the tokens between [[ ... ]] ), then it seems that from the C perspective the choice of syntax is tied to the question whether you want Contracts to be ignorable in C.

We already decided in SG21 that we do not want to, and cannot, make Contracts ignorable in C++, but C may choose differently (not sure what practical implications that would have though).

With that in mind, the discussion here kind of seems to boil down to four people saying they don't like the [[ ... ]] syntax because it's ignorable and Contracts are not ignorable, and one person saying that they prefer the [[ ... ]] syntax because it's ignorable and Contracts should be ignorable...

The main reason why I am in favour of the P2961 syntax is that it looks nothing like attributes so it just completely avoids this whole debate about ignorability. From my perspective, this is the right thing to do because Contracts are, in my view, very different from attributes, have almost nothing in common with attributes, and should therefore not be confused with attributes. But opinions on this matter differ and I respect that.

Cheers,
Timur

> On 6 Oct 2023, at 19:11, Aaron Ballman <aaron_at_[hidden]> wrote:
>
> On Fri, Oct 6, 2023 at 9:58 AM Timur Doumler <cpp_at_[hidden] <mailto:cpp_at_[hidden]>> 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"?
>
> It's a footnote, so we're a bit imprecise with the wording of it. But
> the intent here is "parse" means "lex and eat tokens until the closing
> ]], paying attention to balance (, [, and { with ), ], and }". It's
> "parsing" because of the balanced tokens and needing to find the
> closing ]]. But the goal is for it to be a valid implementation to see
> [[, eat balanced tokens until the closing ]], and drop everything on
> the floor.
>
> ~Aaron
>
>>
>> Cheers,
>> Timur


Received on 2023-10-06 16:23:07