public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/107572] New: cartesian_product_view invokes the begin of input_range twice
@ 2022-11-08 15:25 hewillk at gmail dot com
  2022-11-08 15:35 ` [Bug libstdc++/107572] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: hewillk at gmail dot com @ 2022-11-08 15:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107572

            Bug ID: 107572
           Summary: cartesian_product_view invokes the begin of
                    input_range twice
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hewillk at gmail dot com
  Target Milestone: ---

ranges#L8069:

      auto __it = __detail::__tuple_transform(ranges::begin, _M_bases);
      if (!__empty_tail)
        std::get<0>(__it) =
__detail::__cartesian_common_arg_end(std::get<0>(_M_bases));
      return _Iterator<false>{*this, std::move(__it)};

This *always* invokes begin twice for the first range, which is undefined
behavior when it is an input_range.

testcase (https://godbolt.org/z/7hfP8xM6a):

    #include <ranges>
    #include <fmt/ranges.h>
    #include <sstream>

    std::istringstream ints("0 1 2 3 4");
    struct istream_range {
      auto begin() { return std::istream_iterator<int>{ints}; }
      auto end()   { return std::istream_iterator<int>{}; }
    };

    int main() {
      istream_range r;
      fmt::print("{}\n", std::views::cartesian_product(r)); // prints [(0),
(2), (3), (4)]
    }

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libstdc++/107572] cartesian_product_view invokes the begin of input_range twice
  2022-11-08 15:25 [Bug libstdc++/107572] New: cartesian_product_view invokes the begin of input_range twice hewillk at gmail dot com
@ 2022-11-08 15:35 ` redi at gcc dot gnu.org
  2023-03-07 21:07 ` ppalka at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2022-11-08 15:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107572

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppalka at gcc dot gnu.org
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-11-08
             Status|UNCONFIRMED                 |NEW

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libstdc++/107572] cartesian_product_view invokes the begin of input_range twice
  2022-11-08 15:25 [Bug libstdc++/107572] New: cartesian_product_view invokes the begin of input_range twice hewillk at gmail dot com
  2022-11-08 15:35 ` [Bug libstdc++/107572] " redi at gcc dot gnu.org
@ 2023-03-07 21:07 ` ppalka at gcc dot gnu.org
  2023-03-09 18:25 ` cvs-commit at gcc dot gnu.org
  2023-03-09 18:27 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-03-07 21:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107572

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libstdc++/107572] cartesian_product_view invokes the begin of input_range twice
  2022-11-08 15:25 [Bug libstdc++/107572] New: cartesian_product_view invokes the begin of input_range twice hewillk at gmail dot com
  2022-11-08 15:35 ` [Bug libstdc++/107572] " redi at gcc dot gnu.org
  2023-03-07 21:07 ` ppalka at gcc dot gnu.org
@ 2023-03-09 18:25 ` cvs-commit at gcc dot gnu.org
  2023-03-09 18:27 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-09 18:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107572

--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:3df9760d56662bdf38dd45f7398f003bbd64fdfe

commit r13-6558-g3df9760d56662bdf38dd45f7398f003bbd64fdfe
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Mar 9 13:25:44 2023 -0500

    libstdc++: extraneous begin in cartesian_product_view::end [PR107572]

    ranges::begin() isn't guaranteed to be equality-preserving for non-forward
    ranges, so in cartesian_product_view::end we need to avoid needlessly
    calling begin() on the first range (which could be non-forward) in the
    case where __empty_tail is false as per its specification.

    Since we're already using a variadic lambda to compute __empty_tail, we
    might as well use that same lambda to build up the tuple of iterators
    instead of building it separately via e.g. std::apply or __tuple_transform.

            PR libstdc++/107572

    libstdc++-v3/ChangeLog:

            * include/std/ranges (cartesian_product_view::end): When
            building the tuple of iterators, avoid calling ranges::begin on
            the first range if __empty_tail is false.
            * testsuite/std/ranges/cartesian_product/1.cc (test07): New test.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libstdc++/107572] cartesian_product_view invokes the begin of input_range twice
  2022-11-08 15:25 [Bug libstdc++/107572] New: cartesian_product_view invokes the begin of input_range twice hewillk at gmail dot com
                   ` (2 preceding siblings ...)
  2023-03-09 18:25 ` cvs-commit at gcc dot gnu.org
@ 2023-03-09 18:27 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-03-09 18:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107572

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.0
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Should be fixed, thanks for catching this.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-03-09 18:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-08 15:25 [Bug libstdc++/107572] New: cartesian_product_view invokes the begin of input_range twice hewillk at gmail dot com
2022-11-08 15:35 ` [Bug libstdc++/107572] " redi at gcc dot gnu.org
2023-03-07 21:07 ` ppalka at gcc dot gnu.org
2023-03-09 18:25 ` cvs-commit at gcc dot gnu.org
2023-03-09 18:27 ` ppalka at gcc dot gnu.org

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).