public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Matthias Kretz <m.kretz@gsi.de>
To: <gcc-patches@gcc.gnu.org>, <libstdc++@gcc.gnu.org>
Subject: Re: [PATCH] libstdc++: Implement std::unreachable() for C++23 (P0627R6)
Date: Thu, 31 Mar 2022 17:50:33 +0200	[thread overview]
Message-ID: <3572914.e9J7NaK4W3@minbar> (raw)
In-Reply-To: <20220331153029.1898244-1-jwakely@redhat.com>

I like it. But I'd like it even more if we could have

#elif defined _UBSAN
    __ubsan_invoke_ub("reached std::unreachable()");

But to my knowledge UBSAN has no hooks for the library like this (yet).

and...

On Thursday, 31 March 2022 17:30:29 CEST Jonathan Wakely via Gcc-patches 
wrote:
> diff --git a/libstdc++-v3/include/std/utility
> b/libstdc++-v3/include/std/utility index 0d7f8954c5a..e5b5212381d 100644
> --- a/libstdc++-v3/include/std/utility
> +++ b/libstdc++-v3/include/std/utility
> @@ -186,6 +186,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>      constexpr underlying_type_t<_Tp>
>      to_underlying(_Tp __value) noexcept
>      { return static_cast<underlying_type_t<_Tp>>(__value); }
> +
> +#define __cpp_lib_unreachable 202202L
> +  [[noreturn,__gnu__::__always_inline__]]
> +  void
> +  unreachable()
> +  {
> +#ifdef _GLIBCXX_DEBUG
> +    std::__glibcxx_assert_fail("<utility>", 0, "std::unreachable()",
> +                              "inconceivable!");

Funny message, but it should be more helpful, IMHO. :)

-Matthias

> +#elif defined _GLIBCXX_ASSERTIONS
> +    __builtin_trap();
> +#else
> +    __builtin_unreachable();
> +#endif
> +  }


-- 
──────────────────────────────────────────────────────────────────────────
 Dr. Matthias Kretz                           https://mattkretz.github.io
 GSI Helmholtz Centre for Heavy Ion Research               https://gsi.de
 stdₓ::simd
──────────────────────────────────────────────────────────────────────────

  reply	other threads:[~2022-03-31 15:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-31 15:30 Jonathan Wakely
2022-03-31 15:50 ` Matthias Kretz [this message]
2022-03-31 15:59   ` Xi Ruoyao
2022-03-31 16:01   ` Marc Glisse
2022-03-31 16:05     ` Jonathan Wakely
2022-03-31 18:21       ` Marc Glisse
2022-04-01 11:33         ` Jonathan Wakely
2022-04-01 11:56           ` Matthias Kretz
2022-04-01 13:01             ` Jonathan Wakely
2022-03-31 16:02   ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3572914.e9J7NaK4W3@minbar \
    --to=m.kretz@gsi.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).