Date: Thu, 21 May 2026 20:35:24 +0100
On 21 May 2026 13:32:53 BST, Mital Ashok via Std-Proposals <std-proposals_at_[hidden]> 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>()`.
Maybe use `o.is_valid() ? *o : throw (std::unreachable(),0)` and hope the throw gets optimized away as dead code. ;)
Joke aside, there is P3549 in this area:
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3549r0.html
It proposes a "never" type, and non-returning functions could return that. It would give you the composability that you are looking for without the noise.
>
>It can also be used in some weird cases where you want to ODR-use
>std::declval in a constant expression (e.g., when used as an unknown
>reference)
>
>T is returned instead of add_rvalue_reference_t<T> intentionally
>because of the use case in conditional expressions where we don't want
>to materialise a temporary the other side (so std::unreachable<int>()
>is a prvalue for example). This deviates from std::declval but has
>similar semantics to std::reference_con{struct,vert}s_from_temporary
>(T is prvalue, T& is lvalue, T&& is xvalue), with the unfortunate
>exclusion of array types, but that should not be a big use case.
>
>The above is one of the things that can be discussed about this
>facility. I was mostly wondering if there is anything else I need to
>consider before writing R0 of the proposal
>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>()`.
Maybe use `o.is_valid() ? *o : throw (std::unreachable(),0)` and hope the throw gets optimized away as dead code. ;)
Joke aside, there is P3549 in this area:
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3549r0.html
It proposes a "never" type, and non-returning functions could return that. It would give you the composability that you are looking for without the noise.
>
>It can also be used in some weird cases where you want to ODR-use
>std::declval in a constant expression (e.g., when used as an unknown
>reference)
>
>T is returned instead of add_rvalue_reference_t<T> intentionally
>because of the use case in conditional expressions where we don't want
>to materialise a temporary the other side (so std::unreachable<int>()
>is a prvalue for example). This deviates from std::declval but has
>similar semantics to std::reference_con{struct,vert}s_from_temporary
>(T is prvalue, T& is lvalue, T&& is xvalue), with the unfortunate
>exclusion of array types, but that should not be a big use case.
>
>The above is one of the things that can be discussed about this
>facility. I was mostly wondering if there is anything else I need to
>consider before writing R0 of the proposal
Received on 2026-05-21 19:35:33
