Skip to content

Commit

Permalink
Don't assume repeated evaluation of string literal produce the same p…
Browse files Browse the repository at this point in the history
…ointer

Patch by @zygoloid (#4177).
  • Loading branch information
vitaut committed Sep 28, 2024
1 parent fade652 commit cacc310
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/fmt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit cacc310

Please sign in to comment.