]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Update LWG 4166 changes to concat_view::end() [PR120934]
authorPatrick Palka <ppalka@redhat.com>
Thu, 3 Jul 2025 14:55:17 +0000 (10:55 -0400)
committerPatrick Palka <ppalka@redhat.com>
Thu, 3 Jul 2025 14:55:17 +0000 (10:55 -0400)
In r15-4555-gf191c830154565 we proactively implemented the initial
proposed resolution for LWG 4166 which later turned out to be
insufficient, since we must also require equality_comparable of the
underlying iterators before concat_view could be a common range.

This patch implements the updated P/R, requiring all underlying
iterators to be forward (which implies equality_comparable) before
making concat_view common, which fixes the testcase from this PR.

PR libstdc++/120934

libstdc++-v3/ChangeLog:

* include/std/ranges (concat_view::end): Refine condition
for returning an iterator instead of default_sentinel as
per the updated P/R for LWG 4166.
* testsuite/std/ranges/concat/1.cc (test05): New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/include/std/ranges
libstdc++-v3/testsuite/std/ranges/concat/1.cc

index f764aa7512e330b0984d8d910a2edad3d2ee22ca..3a6710bd0ae134b2d809392bff7a27bce96d5947 100644 (file)
@@ -9735,7 +9735,7 @@ namespace ranges
     end() requires (!(__detail::__simple_view<_Vs> && ...))
     {
       constexpr auto __n = sizeof...(_Vs);
-      if constexpr ((semiregular<iterator_t<_Vs>> && ...)
+      if constexpr (__detail::__all_forward<false, _Vs...>
                    && common_range<_Vs...[__n - 1]>)
        return _Iterator<false>(this, in_place_index<__n - 1>,
                                ranges::end(std::get<__n - 1>(_M_views)));
@@ -9747,7 +9747,7 @@ namespace ranges
     end() const requires (range<const _Vs> && ...) && __detail::__concatable<const _Vs...>
     {
       constexpr auto __n = sizeof...(_Vs);
-      if constexpr ((semiregular<iterator_t<const _Vs>> && ...)
+      if constexpr (__detail::__all_forward<true, _Vs...>
                    && common_range<const _Vs...[__n - 1]>)
        return _Iterator<true>(this, in_place_index<__n - 1>,
                               ranges::end(std::get<__n - 1>(_M_views)));
index 16721912a37d143a26f8a1663749116899550f13..f78ed08a610b2b8c57e41a7adf86f330710b7713 100644 (file)
@@ -99,6 +99,18 @@ test04()
   using type = decltype(v);
 }
 
+void
+test05()
+{
+  // PR libstdc++/120934 - views::concat is ill-formed depending on argument order
+  auto v1 = views::single(1);
+  std::vector<int> vec = {2, 3};
+  auto v2 = views::join(views::transform(vec, views::single));
+
+  static_assert( ranges::range<decltype(views::concat(v1, v2))> );
+  static_assert( ranges::range<decltype(views::concat(v2, v1))> );
+}
+
 int
 main()
 {
@@ -107,4 +119,5 @@ main()
   test02();
   test03();
   test04();
+  test05();
 }