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: Uecker, Martin <Martin.Uecker_at_[hidden]>
Date: Mon, 20 Sep 2021 19:51:26 +0000
Am Montag, den 20.09.2021, 21:22 +0200 schrieb Jens Maurer:
> On 20/09/2021 21.17, Uecker, Martin via Liaison wrote:
> > Am Montag, den 20.09.2021, 19:47 +0300 schrieb Ville Voutilainen via Liaison:
> > > On Mon, 20 Sept 2021 at 19:37, Ryan McDougall via SG21
> > > <sg21_at_[hidden]cpp.org> wrote:
> > > > Can you help me understand the concern here -- is it that C will have to update its grammar
> > > > to
> > > > recognize this syntax as not ignorable, and they would rather not?
> > >
> > > I can't speak for Aaron's concerns, but based on his excellent
> > > explanation, I have mine, which I'd wager are mighty similar to his:
> > >
> > > 1) our design goal for the syntax is that it's sufficiently
> > > incompatible so that older compilers don't just half-accidentally
> > > ignore-chomp it.
> > > 2) we're failing to meet that design goal, because an older C-compiler
> > > can ignore-chomp it and diagnose it
> > > as "attribute ignored". The syntax is not sufficiently different for a
> > > conforming older C-compiler not to mistreat
> > > it, and we fail to achieve the goal of a compiler syntax-checking the
> > > contract annotation.
> > > 3) in other words, the C compiler took our program, and treated it in
> > > a conforming way, it diagnosed a syntax
> > > error with a very misleading diagnostic, but was fully-conforming all the way.
> >
> > Is this somehow different to old C++ compilers?
>
> Really old C++ compilers will see "[[" and complain about
> token soup.
>
> I haven't seen a C++ compiler (of any age) that would
> recognize "[[" but then ignore contained attribute
> entirely.

I haven't seen a C compiler that does this, so
I do not fully understand why there is a difference
between C and C++.

But if we adopt this syntax for contracts, shouldn't
we add generic syntax such as:

[[attribute-token : conditional-expression]]

instead of having only "pre", "post", and "assert"?
Then future extensions would benefit from syntax
(and type?) checking even with older compilers.

Martin



Received on 2021-09-20 14:51:33