C++ Logo


Advanced search

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

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Sat, 7 Oct 2023 17:37:45 +0300
On Sat, 7 Oct 2023 at 17:31, Timur Doumler <cpp_at_[hidden]> wrote:
> > We don't need to waive any deadlines, there's nothing in P2961's
> > content for C++26 that is macro-unfriendly. Everything in it is
> > "pre/post(something)",
> > there are no prefix-brackets or any "pre<magic>/post<magic>" bits in
> > it, just possibly in its future extensions. And those extensions
> > aren't set in stone, and can change.
> Wait, not quite:, there is the syntax for return values in postconditions which is not a future extension – that's being proposed now:
> int f()
> post (ret: ret >= 0);
> Is that colon in there compatible with function-like macros? Because that's not valid function call syntax at least.

Of course it is, the argument list of a macro is just a token or
multiple tokens. Thus:

#define post(X)

void f(int x, int y)
post(ret: ret >= 0)


Received on 2023-10-07 14:37:59