C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::unreachable<T>()

From: Thiago Macieira <thiago_at_[hidden]>
Date: Thu, 21 May 2026 10:15:43 -0700
On Thursday, 21 May 2026 09:18:14 Pacific Daylight Time Andrey Semashev via
Std-Proposals wrote:
> I didn't test extensively, but at least gcc and clang do treat
> __buitin_unreachable correctly, not requiring a dummy return, since like
> forever.

They do. This problem happens with lesser-known compilers that we have to
support in Qt. Probably the Green Hills compiler for INTEGRITY, which is the
only odd one out these days now that QNX and VxWorks use Clang, and ICC is
effectively Clang too.

> That said, you could probably write this as a workaround
>
> return (std::unreachable(), 0);

That is nifty.

> Or just:
>
> std::unreachable();
> return 0;

Except that that there are compilers that complain that you have code *after*
the unreachable marker (MSVC and under Coverity scan)...
 https://msvc.godbolt.org/z/nGPvP1GPs

There are compilers that complain that you didn't write the return, those that
complain that you did, and those that don't care either way.

That's why we introduced the macro.

> In any case, I don't see a strong need for a templated std::unreachable
> with weird semantics re. its return value.

Nor I. I would rather compilers understood std::unreachable() and didn't
complain that I failed to return from where I couldn't have reached.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Data Center - Platform & Sys. Eng.

Received on 2026-05-21 17:15:51