Subject: Re: Missing non-void return on some paths
From: Jonathan Wakely (cxx_at_[hidden])
Date: 2021-05-08 14:18:36
On Sat, 8 May 2021, 19:52 Nevin Liber via SG12, <sg12_at_[hidden]>
> On Thu, May 6, 2021 at 6:47 PM JF Bastien via SG12 <sg12_at_[hidden]>
>> Compilers diagnose when functions can't be proved to return, and I
>> wouldn't work on a codebase without this diagnostic enabled as an error. Is
>> there a valid reason to keep this UB around?
> How does one write an assert-type macro which, when it is disabled, still
> prevents this type of warning/error? Because people do write:
> to mean abort in debug mode, take my chances in release mode.
I think adding std::unreachable(); after the assertion would work for that
purpose. If assertions are enabled, it's true that you'll never get there,
and for release mode, it would be UB to get there (which is the case
already today). Adding unreachable() just tells the compiler not to give a
diagnostic about it.
SG12 list run by email@example.com