From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5E6B73858D28; Wed, 9 Feb 2022 12:40:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5E6B73858D28 From: "zyn7109 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/104465] New: std::vector should satisfy std::ranges::viewable_range (P2415 for -c++2b) Date: Wed, 09 Feb 2022 12:40:27 +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: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: zyn7109 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Feb 2022 12:40:27 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104465 Bug ID: 104465 Summary: std::vector should satisfy std::ranges::viewable_range (P2415 for -c++2b) Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: zyn7109 at gmail dot com Target Milestone: --- Given the following code, ```cpp #include #include #include #include int foo(std::ranges::viewable_range auto) { return 1; } // #1 int foo(auto) { return 0; } // #2 int main() { const std::vector v {"1", "2", "3", "4"}; std::cout << foo(v) << " "; for (auto vv: v | std::views::reverse) std::cout << vv << " "; // #3 } ``` compiling with GCC 12.0.1 (20220208) (https://wandbox.org/permlink/aPZzDSVF0wbtUQF8), the output is "0 4 3 2 1" rather than "1 4 3 2 1" since the overload resolution selects #2 for `foo`. However, as P2415 was merged into C++23 (https://github.com/cplusplus/papers/issues/1085), `std::vector` is now a `viewable_range` and with Clang 15, "1 4 3 2 1" is the result. (https://wandbox.org/permlink/8uzBa0Ot6Yj22Z0l). It seems that P2415 is still not implemented for libstdc++ yet. However, GCC accepts #3 since range was introduced from GCC 10.x (I'm not quite sure whi= ch version) while considering `std::ranges::viewable_range> =3D=3D false`. As the cppreference (https://en.cppreference.com/w/cpp/ranges/reverse_view) or C++= 20 draft suggests (24.7.1 [range.adaptor.object]/1, https://timsong-cpp.github.io/cppwp/n4861/range.adaptors#range.adaptor.obje= ct-1), the range adaptor `std::views::reverse` only takes `viewable_range` as arguments. So it makes me confused and I wonder if I missed something. Clang 13 rejects the above code (https://gcc.godbolt.org/z/xoKesEz7q), whic= h is as expected.=