Subject: Re: Missing non-void return on some paths
From: JF Bastien (cxx_at_[hidden])
Date: 2021-05-08 15:43:20
On Sat, May 8, 2021 at 1:14 PM Nevin Liber via SG12 <sg12_at_[hidden]>
> On Sat, May 8, 2021 at 2:50 PM Jonathan Wakely <cxx_at_[hidden]> wrote:
>> On Sat, 8 May 2021, 20:32 Nevin Liber, <nevin_at_[hidden]> wrote:
>>> On Sat, May 8, 2021 at 2:18 PM Jonathan Wakely <cxx_at_[hidden]> wrote:
>>>> I think adding std::unreachable(); after the assertion would work for
>>>> that purpose.
>>> If I'm reading it correctly, the paper says that unreachable is not
>>> allowed in a constant expression (because calling it is UB).
>> It means that unreachable() cannot be called during constant evaluation.
>> It is allowed in a constexpr function as long as it's not reached. That's
>> the same as falling off the end of a function, isn't it? I don't think it
>> changes anything.
>> During constant evaluation, if you reach the end of a non-void function
>> it's an error. Reaching a call to unreachable would be the same.
>> That is a breaking change for calling assert in a constexpr context
>>> [assertions.assert]. And even if we fix the one in the standard, how can
>>> users write their own?
>> No, because I'm not suggesting adding it to assert. I said add it after
>> the assertion, i.e. in the function containing the assertion.
> For assert(false), sure they can, although now that would require users
> to change code where they have already documented the code is unreachable.
> What about assert(b) when NDEBUG is not defined? JF said that would
> become an unconditional call to std::unreachable, but calling
> std::unreachable invokes UB. From the paper: "The author feels that the
> best way is to make the behavior of std::unreachable() be undefined."
I answered a question, being clear that I wasnât sure I understood it.
Please donât quote the answer as an absolute. I didnât change assert, I
implemented the YOLO() function I though I understood that you wanted. It
seems thatâs not what you wanted?
Yes a change along the lines Iâm hand waving would require documenting that
assert can sometimes do nothing. Isnât that desirable? Or are you saying
itâs needless churn to existing code?
I donât really get what youâre trying to get at. ð¤·ââï¸
SG12 list run by firstname.lastname@example.org