From cefca01e03d9f94270fbcd56d74853d6b68e7912 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 24 Nov 2023 20:02:33 -0800 Subject: [PATCH] Product fix for correctness-damaging typo. Found by `std/ranges/range.utility/range.utility.conv/to.pass.cpp`. --- stl/inc/ranges | 2 +- .../std/tests/P1206R7_ranges_to_misc/test.cpp | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/stl/inc/ranges b/stl/inc/ranges index b71c8e8231f..60228f30299 100644 --- a/stl/inc/ranges +++ b/stl/inc/ranges @@ -10298,7 +10298,7 @@ namespace ranges { } else if constexpr (_Converts_tag_constructible<_Rng, _Container, _Types...>) { return _Container(from_range, _STD forward<_Rng>(_Range), _STD forward<_Types>(_Args)...); } else if constexpr (_Converts_and_common_constructible<_Rng, _Container, _Types...>) { - return _Container(_RANGES begin(_Range), _RANGES end(_Range), _STD forward<_Types...>(_Args)...); + return _Container(_RANGES begin(_Range), _RANGES end(_Range), _STD forward<_Types>(_Args)...); } else if constexpr (_Converts_constructible_insertable<_Rng, _Container, _Types...>) { _Container _Cont(_STD forward<_Types>(_Args)...); if constexpr (_Sized_and_reservable<_Rng, _Container>) { diff --git a/tests/std/tests/P1206R7_ranges_to_misc/test.cpp b/tests/std/tests/P1206R7_ranges_to_misc/test.cpp index 354e365f52a..9ddf8f153aa 100644 --- a/tests/std/tests/P1206R7_ranges_to_misc/test.cpp +++ b/tests/std/tests/P1206R7_ranges_to_misc/test.cpp @@ -67,13 +67,17 @@ constexpr bool test_common_constructible() { using value_type = int; constexpr common_constructible(const int* const first, const int* const last, secret_key_t) - : first_{first}, last_{last} {} + : first_{first}, last_{last}, args_{3} {} + + constexpr common_constructible(const int* const first, const int* const last, secret_key_t, double) + : first_{first}, last_{last}, args_{4} {} const int* begin() const; // not defined const int* end() const; // not defined const int* first_; const int* last_; + int args_; }; int some_ints[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; @@ -82,11 +86,27 @@ constexpr bool test_common_constructible() { std::same_as auto c0 = ranges::to(some_ints, secret_key); assert(c0.first_ == ranges::begin(some_ints)); assert(c0.last_ == ranges::end(some_ints)); + assert(c0.args_ == 3); } { std::same_as auto c1 = some_ints | ranges::to(secret_key); assert(c1.first_ == ranges::begin(some_ints)); assert(c1.last_ == ranges::end(some_ints)); + assert(c1.args_ == 3); + } + + // Verify that more than one argument can be passed after the range: + { + std::same_as auto c2 = ranges::to(some_ints, secret_key, 3.14); + assert(c2.first_ == ranges::begin(some_ints)); + assert(c2.last_ == ranges::end(some_ints)); + assert(c2.args_ == 4); + } + { + std::same_as auto c3 = some_ints | ranges::to(secret_key, 3.14); + assert(c3.first_ == ranges::begin(some_ints)); + assert(c3.last_ == ranges::end(some_ints)); + assert(c3.args_ == 4); } return true;