C++ Logo

std-proposals

Advanced search

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

From: Alejandro Colomar <une+cxx_std-proposals_at_[hidden]>
Date: Thu, 21 May 2026 22:22:42 +0200
Hi Thiago,

On 2026-05-21T09:02:40-0700, 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 expect that a compiler should be able to recognize that a function
ending in

  ...
  unreachable();
 }

does not need a return statement. If a compiler can't fix that , I don't
expect they'll implement a fancy templated unreachable.


Have a lovely night!
Alex

-- 
<https://www.alejandro-colomar.es>

Received on 2026-05-21 20:22:53