[PATCH] libstdc++: Define std::__is_constant_evaluated() for internal use

Jakub Jelinek jakub@redhat.com
Fri Nov 26 12:49:53 GMT 2021


On Fri, Nov 26, 2021 at 12:43:44PM +0000, Jonathan Wakely 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.

While calling the latter might be more maintainable, I think having it
implemented twice would be better, so that std::is_constant_evaluated()
doesn't need to hop through another inline call.
I'd expect people to use std::is_constant_evaluated() in their code quite a
lot, it will take time until they start to use if consteval instead.

	Jakub



More information about the Gcc-patches mailing list