aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/std/ranges
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2024-11-14 17:31:43 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2024-11-14 17:34:29 +0000
commit4a3a0be34f723df192361e43bb48b9292dfe3a54 (patch)
tree8f5ca39b3697ac95ef32c8751c88df37dec830eb /libstdc++-v3/testsuite/std/ranges
parent5673fc0c7bab700395716207a52b3d4736e90ee3 (diff)
downloadgcc-4a3a0be34f723df192361e43bb48b9292dfe3a54.zip
gcc-4a3a0be34f723df192361e43bb48b9292dfe3a54.tar.gz
gcc-4a3a0be34f723df192361e43bb48b9292dfe3a54.tar.bz2
libstdc++: Fix get<0> constraint for lvalue ranges::subrange (LWG 3589)
Apprived at October 2021 plenary. libstdc++-v3/ChangeLog: * include/bits/ranges_util.h (subrange::begin): Fix constraint, as per LWG 3589. * testsuite/std/ranges/subrange/lwg3589.cc: New test.
Diffstat (limited to 'libstdc++-v3/testsuite/std/ranges')
-rw-r--r--libstdc++-v3/testsuite/std/ranges/subrange/lwg3589.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/std/ranges/subrange/lwg3589.cc b/libstdc++-v3/testsuite/std/ranges/subrange/lwg3589.cc
new file mode 100644
index 0000000..1ccc52d
--- /dev/null
+++ b/libstdc++-v3/testsuite/std/ranges/subrange/lwg3589.cc
@@ -0,0 +1,30 @@
+// { dg-do compile { target c++20 } }
+
+// LWG 3589. The const lvalue reference overload of get for subrange does not
+// constrain I to be copyable when N == 0
+
+#include <ranges>
+#include <testsuite_iterators.h>
+
+void
+test_lwg3589()
+{
+ int a[2]{};
+ __gnu_test::test_range<int, __gnu_test::input_iterator_wrapper_nocopy> r(a);
+
+ // Use a generic lambda so we have a dependent context.
+ auto test = [](auto& x)
+ {
+ // This was wrong before the LWG 3589 change:
+ if constexpr (requires { std::ranges::get<0>(x); })
+ (void) std::ranges::get<0>(x);
+
+ // These always worked unconditionally:
+ (void) std::ranges::get<1>(x);
+ (void) std::ranges::get<0>(std::move(x));
+ (void) std::ranges::get<1>(std::move(x));
+ };
+
+ std::ranges::subrange sr(r.begin(), r.end());
+ test(sr);
+}