C++ Logo

std-proposals

Advanced search

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

From: Alejandro Colomar <une+cxx_std-proposals_at_[hidden]>
Date: Fri, 22 May 2026 09:08:13 +0200
Hi Jonathan,

On 2026-05-21T23:47:08+0100, Jonathan Grant wrote:
> > That ship has sailed for unreachable(), I fear. While I would have
> > liked unreachable() to be that tool, I don't think we can do that now.
> >
> > But we could add a new tool, a 'trap' statement, that would be diagnosed
> > if it is not optimized out (maybe as recommended practice).
> >
> > trap; // diagnosed unless proved unreachable.
> >
> >
> > Have a lovely night!
> > Alex
>
> Hi Alex
>
> That's a shame re unreachable()
>
> Is this the idea Martin Uecker __builtin_trap_msg("xyz") mentioned? He said he had a patch for GCC.
> I don't think a good idea to name a feature that issues diagnostic
> warnings a "trap", would confuse with existing debugger terminology.

The name trap is precisely because it would trap at run time. So, the
name is quite appropriate, I think.

Of course, nobody wants their programs to trap, so it would make sense
to diagnose a trap if it isn't optimized out.

> Someone talking about a similar named builtin on llvm, but it still needs the compiler to output a diagnostic (not just trap at runtime)
> https://discourse.llvm.org/t/rfc-adding-builtin-verbose-trap-string-literal/75845/19


Have a lovely day!
Alex

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

Received on 2026-05-22 07:08:23