From cacc3108c5b74020dba7bf3c6d3a7e58cdc085b2 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 28 Sep 2024 08:00:39 -0700 Subject: [PATCH] Don't assume repeated evaluation of string literal produce the same pointer Patch by @zygoloid (#4177). --- include/fmt/base.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index 61115d9f..b5d1c52e 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -2660,8 +2660,9 @@ template struct fstring { template ::value)> FMT_CONSTEVAL FMT_ALWAYS_INLINE fstring(const S& s) : str(s) { + FMT_CONSTEXPR auto sv = string_view(S()); if (FMT_USE_CONSTEVAL) - detail::parse_format_string(s, checker(s, arg_pack())); + detail::parse_format_string(sv, checker(sv, arg_pack())); #ifdef FMT_ENFORCE_COMPILE_STRING static_assert( FMT_USE_CONSTEVAL && sizeof(s) != 0,