C++ Logo

liaison

Advanced search

[wg14/wg21 liaison] Explain contracts use case cdev.ignorable

From: Andrzej Krzemienski <akrzemi1_at_[hidden]>
Date: Wed, 22 Sep 2021 14:17:06 +0200
Hi SG21 and SG22,
I would like to summarize and put more structure into the discussion that
we had in another thread.

I would like to start with one use case bought up by Aaron from the
"Contract Use Cases" document (P1995r0
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1995r0.html>).

Use case cdev.ignorable
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1995r0.html#cdev.ignorable>
:

*As a* C Developer
> *In order to* Write contracts on my functions
> *I want to* Make all contract semantics optional (so as not to change
> WG14-N2385 6.7.11 p2)
>
> *Must Have:* 3, *Nice to Have:* 3, *Not Important:* 23 , *No Answer:* 1
>
> Assuming contracts continue to be rendered as attributes, C
> standardization would require they be semantically optional.
>
> Note that, just as with C++, the ':' in the previous contract syntax does
> not match the grammar for attributes in either language, so by a strict
> reading of the standards there is no obligation to be ignorable. ('[[a:b]]'
> is not a valid attribute and should be diagnosed as invalid on any current
> C or C++ compiler). Many have expressed the view that this opinion is
> pedantic and that the spirit of the law is that anything between [[]]s
> should be ignorable.
>
> Additionally, it is currently a conforming extension to throw away all
> tokens between a pair of [[]]s, and there exist numerous compilers that
> take advantage of that fact which would be broken by requiring behavior of
> any constructs that look like an attribute.
>
I have a couple of questions for whoever feels represented by this use case.

Q1. I see a clash between the "In order to" and "I want to" sections. Why
does a C developer need "all contract semantics optional" to "write
contracts on their function"? Once the contracts are in C, programmers can
certainly write their contracts even if the contract semantics are not
"optional".

Or is this saying that contracts-enabled C compiler processes the contracts
as in P2388R2
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2388r2.html> and
pre-contracts C compiler treats contract annotations as comments?

Q2. The last paragraph in the above use case says "it is currently a
conforming extension to throw away all tokens between a pair of [[]]s".
Does n2385 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2385.pdf>
confirm that this is a conforming extension? Or any earlier/later version?
Or is it just common practice that is non-conformant?

I tried to play with GCC and Clang on any versions I could find in the
Compiler Explorer (https://godbolt.org/z/PsqP57cs4), and it looks like they
either don't parse attributes at all, or report the colon in [[pre: i]] as
syntax error.

Regards,
&rzej;

Received on 2021-09-22 07:17:19