From: Jonathan Wakely Date: Wed, 29 Nov 2023 22:26:28 +0000 (+0000) Subject: libstdc++: Fix std::ranges::to errors X-Git-Tag: basepoints/gcc-15~4119 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18d8a50a042a7faa78626373fdcfe3468c7ae864;p=thirdparty%2Fgcc.git libstdc++: Fix std::ranges::to errors Fix some errors that Patrick noticed, and remove a #if 0 group that I didn't mean to leave in the file. libstdc++-v3/ChangeLog: * include/std/ranges (__detail::__toable): Fix incorrect use of _Range instead of _Cont. (__detail::_ToClosure, __detail::_ToClosure2): Add missing constexpr specifier on constructors. * testsuite/std/ranges/conv/1.cc (_Cont, _Cont2, _Cont3): Remove unnecessary begin() and end() members. (test_constexpr): New function to check range adaptors are usable in constant expressions. --- diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 63bea862c05d..9d4c2e01c4d9 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -9251,7 +9251,7 @@ namespace __detail template constexpr bool __toable = requires { - requires (!input_range<_Range> + requires (!input_range<_Cont> || convertible_to, range_value_t<_Cont>>); }; @@ -9290,7 +9290,7 @@ namespace __detail else if constexpr (constructible_from<_Cont, from_range_t, _Rg, _Args...>) return _Cont(from_range, std::forward<_Rg>(__r), std::forward<_Args>(__args)...); - else if constexpr (requires { common_range<_Rg>; + else if constexpr (requires { requires common_range<_Rg>; typename __iter_category_t>; requires derived_from<__iter_category_t>, input_iterator_tag>; @@ -9346,26 +9346,6 @@ namespace __detail bool operator==(const _InputIter&) const; }; -#if 0 - template typename _Cont, typename _Rg, - typename... _Args> - concept __deduce_expr_1 = requires { - _Cont(std::declval<_Rg>(), std::declval<_Args>()...); - }; - - template typename _Cont, typename _Rg, - typename... _Args> - concept __deduce_expr_2 = requires { - _Cont(from_range, std::declval<_Rg>(), std::declval<_Args>()...); - }; - - template typename _Cont, typename _Rg, - typename... _Args> - concept __deduce_expr_3 = requires(_InputIter<_Rg> __i) { - _Cont(std::move(__i), std::move(__i), std::declval<_Args>()...); - }; -#endif - template typename _Cont, input_range _Rg, typename... _Args> using _DeduceExpr1 @@ -9418,6 +9398,7 @@ namespace __detail tuple...> _M_bound_args; public: + constexpr _ToClosure(_Args&&... __args) : _M_bound_args(std::forward<_Args>(__args)...) { } @@ -9498,6 +9479,7 @@ namespace __detail tuple...> _M_bound_args; public: + constexpr _ToClosure2(_Args&&... __args) : _M_bound_args(std::forward<_Args>(__args)...) { } diff --git a/libstdc++-v3/testsuite/std/ranges/conv/1.cc b/libstdc++-v3/testsuite/std/ranges/conv/1.cc index 0032cf326882..4b6814b1adda 100644 --- a/libstdc++-v3/testsuite/std/ranges/conv/1.cc +++ b/libstdc++-v3/testsuite/std/ranges/conv/1.cc @@ -89,9 +89,6 @@ struct Cont1 : c(r, args...) { } - typename C::iterator begin(); - typename C::iterator end(); - C c; }; @@ -153,9 +150,6 @@ struct Cont2 : c(r, args...) { } - typename C::iterator begin(); - typename C::iterator end(); - C c; }; @@ -186,9 +180,6 @@ struct Cont3 : c(first, last, args...) { } - typename C::iterator begin(); - typename C::iterator end(); - C c; }; @@ -222,10 +213,6 @@ struct Cont4 Cont4() { } Cont4(typename C::allocator_type a) : c(a) { } - // Required to satisfy range - typename C::iterator begin() { return c.begin(); } - typename C::iterator end() { return c.end(); } - // Satisfying container-insertable requires either this ... template requires UsePushBack @@ -254,7 +241,9 @@ struct Cont4 used_reserve = true; } - // Required to satisfy reservable-container + // Satisfying sized_range is required to satisfy reservable-container + typename C::iterator begin() { return c.begin(); } + typename C::iterator end() { return c.end(); } auto size() const { return c.size(); } // Required to satisfy reservable-container @@ -355,6 +344,17 @@ test_nodiscard() std::ranges::to(); // { dg-warning "ignoring return" } } +void +test_constexpr() +{ + constexpr int x = [](int i) { + auto c1 = std::views::iota(1, i) | std::ranges::to>(); + auto c2 = std::views::iota(i, 10) | std::ranges::to(); + return c1[0] + c2[0]; + }(5); + static_assert(x == 6); +} + int main() { test_p1206r7_examples(); @@ -366,4 +366,5 @@ int main() test_2_2(); test_lwg3984(); test_nodiscard(); + test_constexpr(); }