C++ Logo

liaison

Advanced search

Re: [wg14/wg21 liaison] the syntax for contract annotations in C++

From: Aaron Ballman <aaron_at_[hidden]>
Date: Mon, 20 Sep 2021 10:20:39 -0400
On Mon, Sep 20, 2021 at 9:59 AM Andrzej Krzemienski via Liaison
<liaison_at_[hidden]> wrote:
>
> Hi SG22,
> I hope I am using the right address for addressing the C/C++ liaison study group.

You are!

> I was advised to consult the group about the syntax intended to be used for contract annotations in C++ (preconditions, postconditions, and assertions).
>
> Here is a link to the paper describing the proposed addition
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2388r2.html
>
> The syntax is based on the contract proposal that targeted C++20. In short:
>
> ```
> int select(int i, int j)
> [[pre: i >= 0]] // a function precondition
> [[pre: j >= 0]] // a function precondition
> [[post r: r >= 0]] // a function postcondition, r names the return value
> {
> [[assert: _state >= 0]]; // block-scope assertion
> if (_state == 0) return i;
> else return j;
> }
> ```
>
> The syntax was chosen for the following reason:
> * Some conceptual resemblance to attributes: removing them from a correct (bug free) program does not affect the semantics
> * Word `assert` can be used without conflicting with macro `assert()`.
>
> I would like to know your opinion on how this is compatible with the plans for C.
>
> This is my first interaction with SG22, so I do not know how to proceed. Should I give you a presentation of the feature in Zoom? Should we set up a telecon to discuss, or is it fine to only exchange emails?
>
> I would appreciate your guidance here.

I've added the SG22 tag to the paper in the issue tracker, so we won't
lose track of it. I definitely would like to schedule this for
discussion in SG22 as I think this functionality would be
exceptionally useful to C programmers, so keeping the door open for C
to adopt the same syntax is very valuable.

Are you hoping to get P2388 into C++23? The Oct SG22 meeting agenda is
basically set at this point, but I could try to schedule for Nov if
you're aiming for C++23.

> I am also not subscribed to liaison_at_[hidden],and in fact I do not know where to apply for the subscription, so I would appreciate a direct answer to this email.

You can sign up at https://lists.isocpp.org/mailman/listinfo.cgi/liaison

Thanks!

~Aaron

>
> Regards,
> Andrzej KrzemieĊ„ski
> _______________________________________________
> Liaison mailing list
> Liaison_at_[hidden]
> Subscription: https://lists.isocpp.org/mailman/listinfo.cgi/liaison
> Link to this post: http://lists.isocpp.org/liaison/2021/09/0715.php

Received on 2021-09-20 09:22:03