public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Jonathan Wakely <jwakely@redhat.com>
Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] libstdc++: Define std::__is_constant_evaluated() for internal use
Date: Fri, 26 Nov 2021 13:39:50 +0100	[thread overview]
Message-ID: <20211126123950.GG2646553@tucnak> (raw)
In-Reply-To: <20211126122925.1626170-1-jwakely@redhat.com>

On Fri, Nov 26, 2021 at 12:29:25PM +0000, Jonathan Wakely via Gcc-patches wrote:
> +  // Internal version of std::is_constant_evaluated() for C++11.
> +  // This can be used without checking if the compiler supports the built-in.
> +  constexpr inline bool
> +  __is_constant_evaluated() noexcept
> +  {

When you have such a nice one spot, shouldn't it:
#if __cpp_if_consteval >= 202106L 
  if consteval
    {
      return true;
    }
  else
    {
      return false;
    }
#elif __has_builtin(__builtin_is_constant_evaluated)
...

Theoretically not all compilers need to support the builtin and in C++23
mode if consteval should be slightly more efficient.

One disadvantage of std::__is_constant_evaluated() is that Marek's
warning for if constexpr (std::is_constant_evaluated()) will not trigger
if __is_constant_evaluated() is used instead.  But I'd hope testsuite
coverage would discover it quickly if such bug would appear...

	Jakub


  parent reply	other threads:[~2021-11-26 12:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-26 12:29 Jonathan Wakely
2021-11-26 12:38 ` Ville Voutilainen
2021-11-26 12:39 ` Jakub Jelinek [this message]
2021-11-26 12:43   ` Jonathan Wakely
2021-11-26 12:49     ` Jakub Jelinek
2021-11-26 23:26     ` [PATCH v2] " 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=20211126123950.GG2646553@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jwakely@redhat.com \
    --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).