https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90784

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
While you have a constexpr function, you are not calling it in a constexpr
context (to be precise, it is not manifestly constant-evaluated), you'd need to
use
  constexpr auto x = Test(_psz);
for that instead (or make Test consteval in C++20).
std::is_constant_evaluated does only exactly what the standard requires it to
do.
The reason why you don't get it all compile time evaluated is that if it is not
is_constant_evaluated, the std length will then use a builtin function instead
of evaluating it a character by character, but that makes it fail when the
compiler tries to evaluate it as a non-manifestly constant-evaluated constant
expression.  And your own length on the other side wants to be evaluated only
as a constant expression, otherwise it isn't optimized well.
So, either don't mix the std code with your implementation, or e.g. use
std::is_constant_evaluated and use strlen in your implementation as well.

Reply via email to