diff --git a/libcxx/include/__string b/libcxx/include/__string --- a/libcxx/include/__string +++ b/libcxx/include/__string @@ -337,8 +337,21 @@ static _LIBCPP_CONSTEXPR_AFTER_CXX14 int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT; - static inline size_t _LIBCPP_CONSTEXPR_AFTER_CXX14 - length(const char_type* __s) _NOEXCEPT {return __builtin_strlen(__s);} + + static inline size_t _LIBCPP_CONSTEXPR_AFTER_CXX14 length(const char_type* __s) _NOEXCEPT { + // GCC currently does not support __builtin_strlen during constant evaluation. + // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70816 +#ifdef _LIBCPP_COMPILER_GCC + if (__libcpp_is_constant_evaluated()) { + size_t __i = 0; + for (; __s[__i] != char_type('\0'); ++__i) + ; + return __i; + } +#endif + return __builtin_strlen(__s); + } + static _LIBCPP_CONSTEXPR_AFTER_CXX14 const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT; static inline _LIBCPP_CONSTEXPR_AFTER_CXX17 diff --git a/libcxx/test/std/strings/string.view/string.view.ops/copy.pass.cpp b/libcxx/test/std/strings/string.view/string.view.ops/copy.pass.cpp --- a/libcxx/test/std/strings/string.view/string.view.ops/copy.pass.cpp +++ b/libcxx/test/std/strings/string.view/string.view.ops/copy.pass.cpp @@ -6,9 +6,6 @@ // //===----------------------------------------------------------------------===// -// GCC's __builtin_strlen isn't constexpr yet -// XFAIL: gcc-11 && !(c++11 || c++14 || c++17) - // // size_type copy(charT* s, size_type n, size_type pos = 0) const;