From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1D9443858D20; Tue, 8 Nov 2022 15:25:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D9443858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667921147; bh=sg4ULXSK/DkULliKclu120Xx/nWK+SZxrLBcUwcCTQw=; h=From:To:Subject:Date:From; b=i0HqEFGoWv+5GR3CuwK55cysPyFMbKHUHH97UX0Ek/LhF9pV8990ZGCyfDAoKPNbp fu/Sxxd6pEfRN1by3pNBf9RIEASVHQX5Xtx3G1OlIIeahZNXxbe+Kjrm3S3ZekkxEK 2RGB8lbVWV7C725aNnyqzo+weLkzGiZ+px20EPsA= From: "hewillk at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/107572] New: cartesian_product_view invokes the begin of input_range twice Date: Tue, 08 Nov 2022 15:25:46 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hewillk at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107572 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 =3D __detail::__tuple_transform(ranges::begin, _M_bases); if (!__empty_tail) std::get<0>(__it) =3D __detail::__cartesian_common_arg_end(std::get<0>(_M_bases)); return _Iterator{*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 #include #include std::istringstream ints("0 1 2 3 4"); struct istream_range { auto begin() { return std::istream_iterator{ints}; } auto end() { return std::istream_iterator{}; } }; int main() { istream_range r; fmt::print("{}\n", std::views::cartesian_product(r)); // prints [(0), (2), (3), (4)] }=