C++ Logo

liaison

Advanced search

Re: [wg14/wg21 liaison] unreachable control flow

From: Jens Maurer <Jens.Maurer_at_[hidden]>
Date: Thu, 20 May 2021 00:49:37 +0200
On 20/05/2021 00.35, Richard Smith wrote:
> On Mon, May 17, 2021 at 12:34 PM Jens Maurer via Liaison <liaison_at_[hidden] <mailto:liaison_at_[hidden]>> wrote:

> That also feels like an additional layer. Maybe
>
> #ifdef NDEBUG
> #define assume(b) if (!b) unreachable();
> #else
> #define assume(b) assert(b)
> #endif
>
> would help here, but the basic facility "unreachable" should
> still be available regardless.
>
>
> This approach does not make for a good, portable 'assume' implementation. At least some optimizing compilers will transform
>
> f();
> if (!b) unreachable();
> g();
>
> ... into ...
>
> f();
> g();
>
> ... without retaining any knowledge that 'b' was assumed to be true. If we want the functionality of assume(b), we shouldn't assume we get it as a side-effect of adding unreachable().

Fine, but we can't reasonably force the compiler to act on
knowledge about "b" regardless. Put differently, what would
the specification-level meaning of assume(b) be?

Jens

Received on 2021-05-19 17:49:45