diff --git a/include/fmt/core.h b/include/fmt/core.h index 2bac1cb3..a8402303 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -422,11 +422,17 @@ template class basic_string_view { */ FMT_CONSTEXPR_CHAR_TRAITS FMT_INLINE - basic_string_view(const Char* s) : data_(s) { + basic_string_view(const Char* s) : data_(s), size_(0) { + // This test is needed to ensure that this constructor is constexpr in C++17 + // modes. +#ifdef __cpp_lib_is_constant_evaluated if (detail::const_check(std::is_same::value && - !detail::is_constant_evaluated())) + !detail::is_constant_evaluated())) { + // Call strlen directly for better code generation in non-optimized + // builds. size_ = std::strlen(reinterpret_cast(s)); - else + } else +#endif size_ = std::char_traits::length(s); }