diff --git a/libcxx/include/__string b/libcxx/include/__string --- a/libcxx/include/__string +++ b/libcxx/include/__string @@ -337,8 +337,20 @@ 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 { +#ifdef _LIBCPP_COMPILER_GCC + if (__libcpp_is_constant_evaluated()) { + size_t __i = 0; + for (; __s[i] != '\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