Date: Thu, 21 May 2026 16:02:17 +0300
On 21 May 2026 15:32, Mital Ashok via Std-Proposals wrote:
> This should be a non-breaking extension.
> Add a templated function:
>
> template<class T>
> [[noreturn]] T unreachable() {
> unreachable();
> }
>
> This is useful in ternary conditional expressions, like `o.is_valid()
> ? *o : std::unreachable<O::value_type>()`.
How is this different from just `*o`?
std::unreachable is useful to show the compiler that a certain branch of
code is not supposed to be reached in execution, which is necessary when
the said branch has to exist. In your example, the branch doesn't have
to exist and can simply be eliminated.
> This should be a non-breaking extension.
> Add a templated function:
>
> template<class T>
> [[noreturn]] T unreachable() {
> unreachable();
> }
>
> This is useful in ternary conditional expressions, like `o.is_valid()
> ? *o : std::unreachable<O::value_type>()`.
How is this different from just `*o`?
std::unreachable is useful to show the compiler that a certain branch of
code is not supposed to be reached in execution, which is necessary when
the said branch has to exist. In your example, the branch doesn't have
to exist and can simply be eliminated.
Received on 2026-05-21 13:02:25
