From: Patrick Palka Date: Tue, 18 Apr 2023 11:21:07 +0000 (-0400) Subject: libstdc++: Fix typo in views::as_const's operator() [PR109525] X-Git-Tag: upstream/13.1.0~32 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4dc8c0b62d91d239b88cc81bbb8f4fbde317fde6;p=platform%2Fupstream%2Fgcc.git libstdc++: Fix typo in views::as_const's operator() [PR109525] PR libstdc++/109525 libstdc++-v3/ChangeLog: * include/std/ranges (views::_AsConst::operator()): Add missing const to constant_range test. * testsuite/std/ranges/adaptors/as_const/1.cc (test02): Improve formatting. Adjust expected type of v2. (test03): New test. (cherry picked from commit 4ec4ceafcc04ec7bafb1857cf6d491030440a765) --- diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 283d757..1714f3f 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -9025,7 +9025,7 @@ namespace views::__adaptor return ref_view(static_cast (std::forward<_Range>(__r).base())); else if constexpr (is_lvalue_reference_v<_Range> - && constant_range<_Tp> + && constant_range && !view<_Tp>) return ref_view(static_cast(__r)); else diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/as_const/1.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/as_const/1.cc index d04645f..ac1be74 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/as_const/1.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/as_const/1.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -36,29 +37,37 @@ test01() constexpr bool test02() { - std::same_as> auto v1 - = views::empty | views::as_const; - int x[] = {1, 2, 3}; - std::same_as>> auto v2 - = x | views::as_const; - std::same_as> auto v3 - = std::as_const(x) | views::as_const; - std::same_as> auto v4 - = std::as_const(x) | views::all | views::as_const; - std::same_as> auto v5 - = std::span{x, x+3} | views::as_const; - - std::same_as>>> auto v6 - = x | views::chunk(2) | views::as_const; + std::same_as> + auto v1 = views::empty | views::as_const; + std::same_as> + auto v2 = x | views::as_const; + std::same_as> + auto v3 = std::as_const(x) | views::as_const; + std::same_as> + auto v4 = std::as_const(x) | views::all | views::as_const; + std::same_as> + auto v5 = std::span{x, x+3} | views::as_const; + std::same_as>>> + auto v6 = x | views::chunk(2) | views::as_const; VERIFY( v6.size() == 2 ); return true; } +void +test03() +{ + // PR libstdc++/109525 + std::vector v; + std::same_as>> + auto r = views::as_const(v); +} + int main() { static_assert(test01()); static_assert(test02()); + test03(); }