Date: Thu, 21 May 2026 19:18:14 +0300
On 21 May 2026 19:02, Thiago Macieira via Std-Proposals wrote:
> On Thursday, 21 May 2026 08:58:29 Pacific Daylight Time Andrey Semashev via
> Std-Proposals wrote:
>>> This happens more commonly with switches over full enumerations, without
>>>
>>> default:
>>> switch (e) {
>>> case E::A: return 1;
>>> case E::B: return -1;
>>> }
>>> Q_UNREACHABLE_RETURN(0);
>>
>> This still doesn't necessitate the templated std::unreachable, the
>> non-template one would suffice.
>
> If the compilers don't get fixed but we did get the templated one, I'd expect
> the code to get rewritten as:
>
> return std::unreachable<int>();
I didn't test extensively, but at least gcc and clang do treat
__buitin_unreachable correctly, not requiring a dummy return, since like
forever.
https://godbolt.org/z/f51Ez818q
That said, you could probably write this as a workaround
return (std::unreachable(), 0);
Or just:
std::unreachable();
return 0;
which is what I would probably write, if __buitin_unreachable didn't work.
In any case, I don't see a strong need for a templated std::unreachable
with weird semantics re. its return value.
> On Thursday, 21 May 2026 08:58:29 Pacific Daylight Time Andrey Semashev via
> Std-Proposals wrote:
>>> This happens more commonly with switches over full enumerations, without
>>>
>>> default:
>>> switch (e) {
>>> case E::A: return 1;
>>> case E::B: return -1;
>>> }
>>> Q_UNREACHABLE_RETURN(0);
>>
>> This still doesn't necessitate the templated std::unreachable, the
>> non-template one would suffice.
>
> If the compilers don't get fixed but we did get the templated one, I'd expect
> the code to get rewritten as:
>
> return std::unreachable<int>();
I didn't test extensively, but at least gcc and clang do treat
__buitin_unreachable correctly, not requiring a dummy return, since like
forever.
https://godbolt.org/z/f51Ez818q
That said, you could probably write this as a workaround
return (std::unreachable(), 0);
Or just:
std::unreachable();
return 0;
which is what I would probably write, if __buitin_unreachable didn't work.
In any case, I don't see a strong need for a templated std::unreachable
with weird semantics re. its return value.
Received on 2026-05-21 16:18:18
