C++ Logo

liaison

Advanced search

Re: [wg14/wg21 liaison] unreachable control flow

From: Miguel Ojeda <miguel.ojeda.sandonis_at_[hidden]>
Date: Wed, 19 May 2021 10:45:11 +0200
On Wed, May 19, 2021 at 9:46 AM Jā‚‘ā‚™ā‚› Gustedt <jens.gustedt_at_[hidden]> wrote:
>
> yes, sorry, I always have difficulties to wrap my head around these
> things so I have to talk them out to convince myself ;-)

No problem! :-)

To clarify further, as a summary:

  Safe version (calls `abort()`, panics, etc.):
    - P0627: none.
    - Rust: `unreachable()`.
    - Zig: `unreachable` (on `Debug`, `ReleaseSafe` and tests).

  Unsafe version (introduces UB, allows to optimize):
    - P0627: `unreachable()`.
    - Rust: `unreachable_unchecked()`.
    - Zig: `unreachable` (on `ReleaseFast`).

On Swift, the UB version can be approximated under `-Ounchecked` using
`assert(false)`, e.g. https://godbolt.org/z/hsjKMWP55. So it is pretty
similar to Zig's approach.

Cheers,
Miguel

Received on 2021-05-19 03:45:25