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 via email to