Don't assume repeated evaluation of string literal produce the same pointer

Patch by @zygoloid (#4177).
This commit is contained in:
Victor Zverovich
2024-09-28 08:00:39 -07:00
parent fade652ade
commit cacc3108c5

View File

@ -2660,8 +2660,9 @@ template <typename... T> struct fstring {
template <typename S,
FMT_ENABLE_IF(std::is_convertible<const S&, string_view>::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<char>(s, checker(s, arg_pack()));
detail::parse_format_string<char>(sv, checker(sv, arg_pack()));
#ifdef FMT_ENFORCE_COMPILE_STRING
static_assert(
FMT_USE_CONSTEVAL && sizeof(s) != 0,