https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86590
--- Comment #14 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Richard Biener from comment #10) > Caused by r249137 which claims __builtin_strlen isn't usable in constexpr > functions (well, why not? why not make it so?). Yes please. That's what PR c++/80265 asks for. (In reply to Richard Biener from comment #12) > So C++ is basically lacking a feature to give two implementations, one > suitable for constexpr evaluation and one for non-constexpr contexts. That's been asked for repeatedly but will never happen, instead this is being added to C++2a: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0595r1.html So we'd do static _GLIBCXX17_CONSTEXPR size_t length(const char_type* __s) { #if __cplusplus >= 201703L if (std::is_constant_evaluated()) // naive loop #endif return __builtin_strlen(__s); } That way the dumb loop is only ever used in constant evaluation of constant expressions, not every time that __builtin_constant_p is true because the optimiser can see the input. > Maybe it's easier to retro-fit sth like that into the compiler? > > if (__constexpr_evaluation_p) Implementing std::is_constant_evaluated() would be great.