From d1f7bbac17dcc0a15acd7f37cae01e0bf992fc31 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 2 Oct 2021 07:03:08 -0700 Subject: [PATCH] Don't use strlen in constexpr --- include/fmt/core.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 18cdf2237d042..30211d5fcc9c9 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -314,11 +314,13 @@ FMT_BEGIN_DETAIL_NAMESPACE // (void)var does not work on many Intel compilers. template FMT_CONSTEXPR void ignore_unused(const T&...) {} -constexpr FMT_INLINE auto is_constant_evaluated() FMT_NOEXCEPT -> bool { +constexpr FMT_INLINE auto is_constant_evaluated(bool default_value = false) + FMT_NOEXCEPT -> bool { #ifdef __cpp_lib_is_constant_evaluated + ignore_unused(default_value); return std::is_constant_evaluated(); #else - return false; + return default_value; #endif } @@ -426,7 +428,7 @@ template class basic_string_view { FMT_INLINE basic_string_view(const Char* s) : data_(s) { if (detail::const_check(std::is_same::value && - !detail::is_constant_evaluated())) + !detail::is_constant_evaluated(true))) size_ = std::strlen(reinterpret_cast(s)); else size_ = std::char_traits::length(s);