From 1c5883bef081a5cce75bdc4dab0ce922d3bb600f Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 28 Sep 2024 08:20:24 -0700 Subject: [PATCH] Test nondeterministic conversion to format string --- test/base-test.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/base-test.cc b/test/base-test.cc index cc0901a4..1ee0c657 100644 --- a/test/base-test.cc +++ b/test/base-test.cc @@ -868,3 +868,17 @@ TEST(base_test, format_to_custom_container) { auto c = custom_container(); fmt::format_to(std::back_inserter(c), ""); } + +struct nondeterministic_format_string { + mutable int i = 0; + FMT_CONSTEXPR operator string_view() const { + return string_view("{}", i++ != 0 ? 2 : 0); + } +}; + +TEST(base_test, no_repeated_format_string_conversions) { +#if !FMT_GCC_VERSION + char buf[10]; + fmt::format_to(buf, nondeterministic_format_string()); +#endif +}