C++ Logo

liaison

Advanced search

Re: [wg14/wg21 liaison] [isocpp-sg21] Telecon to review P2388R1 Minimum Contract Support: either Ignore or Check_and_abort

From: Aaron Ballman <compatibility.sg.chair_at_[hidden]>
Date: Mon, 20 Sep 2021 12:11:48 -0400
On Mon, Sep 20, 2021 at 12:02 PM Ville Voutilainen via Liaison
<liaison_at_[hidden]> wrote:
>
> On Mon, 20 Sept 2021 at 18:57, Aaron Ballman
> <compatibility.sg.chair_at_[hidden]> wrote:
> > > > There are compilers for which the implementation strategy for all
> > > > attributes is to note the [[ that opens an attribute specifier, eat
> > > > all balanced tokens up to the closing ]], and diagnose the entire bit
> > > > as "attribute ignored" (as a warning). You cannot do that with
> > It is a conforming strategy because of the laxity in what diagnostics
> > are required for conformance. "attribute ignored" is a low-quality
> > diagnostic for [[12]] but is still a conforming implementation. The
> > issue with contracts is that there are additional semantics that can't
> > be ignored.
>
> Oops, sorry, I managed to convince my brain to not read the "and
> diagnose" part of your explanation. :D

No worries, this is twisty-windy stuff at the best of times!

> Do we have any concrete suggestions for making it easier for a C
> compiler to barf harder on a C++ contract annotation,
> perhaps in a way that doesn't require the C compiler to change its
> attribute-processing approach?

None that have been polled by anyone to my knowledge, but the one that
I think would be the most palatable would be to introduce keywords:

int select(int i, int j, int *ptr)
  co_pre(i >= 0)
  co_post(j >= 0) {
  co_assert(ptr != 0);
  if (*ptr == 12)
    return i;
  return j;
}

The co_ prefix obviously stands for "contract". :-) But more
seriously, using new syntax for this would force the point. This has
the extra added benefit of not confusing users into thinking the
contract is part of the function *type* by virtue of the syntactic
location of [[something]] after the parameter list in a function
declaration.

~Aaron

> _______________________________________________
> 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/0726.php

Received on 2021-09-20 11:13:21