public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r13-6562] libstdc++: Implement LWG 3820/3849 changes to cartesian_product_view
Date: Thu,  9 Mar 2023 18:41:39 +0000 (GMT)	[thread overview]
Message-ID: <20230309184139.5C3E43858C5E@sourceware.org> (raw)

https://gcc.gnu.org/g:96abc8222464fb1c4fba9f2ffe3fd1b081a9196e

commit r13-6562-g96abc8222464fb1c4fba9f2ffe3fd1b081a9196e
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Mar 9 13:41:03 2023 -0500

    libstdc++: Implement LWG 3820/3849 changes to cartesian_product_view
    
    The LWG 3820 testcase revealed a bug in _M_advance, which this patch
    also fixes.
    
    libstdc++-v3/ChangeLog:
    
            * include/std/ranges
            (cartesian_product_view::_Iterator::_Iterator): Remove
            constraint on default constructor as per LWG 3849.
            (cartesian_product_view::_Iterator::_M_prev): Adjust position
            of _Nm > 0 test as per LWG 3820.
            (cartesian_product_view::_Iterator::_M_advance): Perform bounds
            checking only on sized cartesian products.
            * testsuite/std/ranges/cartesian_product/1.cc (test08): New test.

Diff:
---
 libstdc++-v3/include/std/ranges                    | 23 ++++++++++++----------
 .../testsuite/std/ranges/cartesian_product/1.cc    |  9 +++++++++
 2 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index f6809413ee1..0725e700c47 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -8224,7 +8224,7 @@ namespace views::__adaptor
 				    range_reference_t<__maybe_const_t<_Const, _Vs>>...>;
     using difference_type = decltype(cartesian_product_view::_S_difference_type());
 
-    _Iterator() requires forward_range<__maybe_const_t<_Const, _First>> = default;
+    _Iterator() = default;
 
     constexpr
     _Iterator(_Iterator<!_Const> __i)
@@ -8389,12 +8389,12 @@ namespace views::__adaptor
     _M_prev()
     {
       auto& __it = std::get<_Nm>(_M_current);
-      if (__it == ranges::begin(std::get<_Nm>(_M_parent->_M_bases)))
-	{
-	  __it = __detail::__cartesian_common_arg_end(std::get<_Nm>(_M_parent->_M_bases));
-	  if constexpr (_Nm > 0)
+      if constexpr (_Nm > 0)
+	if (__it == ranges::begin(std::get<_Nm>(_M_parent->_M_bases)))
+	  {
+	    __it = __detail::__cartesian_common_arg_end(std::get<_Nm>(_M_parent->_M_bases));
 	    _M_prev<_Nm - 1>();
-	}
+	  }
       --__it;
     }
 
@@ -8415,10 +8415,13 @@ namespace views::__adaptor
 	  if constexpr (_Nm == 0)
 	    {
 #ifdef _GLIBCXX_ASSERTIONS
-	      auto __size = ranges::ssize(__r);
-	      auto __begin = ranges::begin(__r);
-	      auto __offset = __it - __begin;
-	      __glibcxx_assert(__offset + __x >= 0 && __offset + __x <= __size);
+	      if constexpr (sized_range<__maybe_const_t<_Const, _First>>)
+		{
+		  auto __size = ranges::ssize(__r);
+		  auto __begin = ranges::begin(__r);
+		  auto __offset = __it - __begin;
+		  __glibcxx_assert(__offset + __x >= 0 && __offset + __x <= __size);
+		}
 #endif
 	      __it += __x;
 	    }
diff --git a/libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc b/libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc
index f52c2b96d58..ef2ece4a168 100644
--- a/libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc
+++ b/libstdc++-v3/testsuite/std/ranges/cartesian_product/1.cc
@@ -201,6 +201,14 @@ test07()
   VERIFY( i == 5 );
 }
 
+void
+test08()
+{
+  // LWG 3820
+  auto r = views::cartesian_product(views::iota(0));
+  r.begin() += 3;
+}
+
 int
 main()
 {
@@ -211,4 +219,5 @@ main()
   test05();
   static_assert(test06());
   test07();
+  test08();
 }

                 reply	other threads:[~2023-03-09 18:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230309184139.5C3E43858C5E@sourceware.org \
    --to=ppalka@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).