C++ Logo

sg12

Advanced search

Re: [SG12] Missing non-void return on some paths

From: JF Bastien <cxx_at_[hidden]>
Date: Sat, 8 May 2021 13:43:20 -0700
On Sat, May 8, 2021 at 1:14 PM Nevin Liber via SG12 <sg12_at_[hidden]>
wrote:

> 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. 🤷‍♂️

>

Received on 2021-05-08 15:43:35