public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: "libstdc++" <libstdc++@gcc.gnu.org>,
	gcc Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] libstdc++: Define std::__is_constant_evaluated() for internal use
Date: Fri, 26 Nov 2021 12:43:44 +0000	[thread overview]
Message-ID: <CACb0b4kL4wLDb85u6ppdD6eTK4PcS4gEL6tVqwryxeue6ntr+g@mail.gmail.com> (raw)
In-Reply-To: <20211126123950.GG2646553@tucnak>

On Fri, 26 Nov 2021 at 12:39, Jakub Jelinek wrote:
>
> 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.

Yes, good idea. We actually still have two spots, because we still
have std::is_constant_evaluated as well, which is only defined if it
actually works. But we can use the same implementation in there (or
make it call std::__is_constant_evaluated()). I'll prepare a new patch
soon.

> 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...

Yes, and I hope I won't make that mistake anyway, or miss it in reviews.

It's a good warning for users, but I like to think I don't need it
(and now we start the sweepstake on how many days until I push a patch
making exactly that mistake ;-)


  reply	other threads:[~2021-11-26 12:43 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
2021-11-26 12:43   ` Jonathan Wakely [this message]
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=CACb0b4kL4wLDb85u6ppdD6eTK4PcS4gEL6tVqwryxeue6ntr+g@mail.gmail.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@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).