From fc723fd6c707064cca9ed95cf4526a955e3cd2b7 Mon Sep 17 00:00:00 2001 From: Justin Riddell Date: Thu, 23 May 2024 20:39:11 +0100 Subject: [PATCH] Fix regression in #3710 (#3968) Regression introduced in 11f2f30 Already have a test for this, but needed to make __cpp_lib_ranges smaller to enable it --- include/fmt/ranges.h | 3 ++- test/ranges-test.cc | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 57ccb6a0..e19caf58 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -495,7 +495,8 @@ struct range_formatter< for (; it != end; ++it) { if (i > 0) out = detail::copy(separator_, out); ctx.advance_to(out); - out = underlying_.format(mapper.map(*it), ctx); + auto&& item = *it; // Need an lvalue + out = underlying_.format(mapper.map(item), ctx); ++i; } out = detail::copy(closing_bracket_, out); diff --git a/test/ranges-test.cc b/test/ranges-test.cc index 37a7aec8..e05ae148 100644 --- a/test/ranges-test.cc +++ b/test/ranges-test.cc @@ -506,7 +506,7 @@ TEST(ranges_test, format_join_adl_begin_end) { #endif // FMT_RANGES_TEST_ENABLE_JOIN -#if defined(__cpp_lib_ranges) && __cpp_lib_ranges >= 202302L +#if defined(__cpp_lib_ranges) && __cpp_lib_ranges >= 202207L TEST(ranges_test, nested_ranges) { auto l = std::list{1, 2, 3}; auto r = std::views::iota(0, 3) | std::views::transform([&l](auto i) {