]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Implement LWG 3470 change to ranges::subrange
authorPatrick Palka <ppalka@redhat.com>
Tue, 19 Oct 2021 22:07:05 +0000 (18:07 -0400)
committerPatrick Palka <ppalka@redhat.com>
Tue, 12 Apr 2022 12:37:27 +0000 (08:37 -0400)
libstdc++-v3/ChangeLog:

* include/bits/ranges_util.h
(__detail::__uses_nonqualification_pointer_conversion): Define
and use it ...
(__detail::__convertible_to_nonslicing): ... here, as per LWG 3470.
* testsuite/std/ranges/subrange/1.cc: New test.

(cherry picked from commit 98af6b86bc6cac705474c14bb3f9748f6866c859)

libstdc++-v3/include/bits/ranges_util.h
libstdc++-v3/testsuite/std/ranges/subrange/1.cc [new file with mode: 0644]

index ebcd233fdb1036bad0a1a7541a60162fc3e088de..647670812f6840086e3e6ffb3000c519d7bec998 100644 (file)
@@ -161,11 +161,16 @@ namespace ranges
 
   namespace __detail
   {
-    template<class _From, class _To>
+    template<typename _From, typename _To>
+      concept __uses_nonqualification_pointer_conversion
+       = is_pointer_v<_From> && is_pointer_v<_To>
+         && !convertible_to<remove_pointer_t<_From>(*)[],
+                            remove_pointer_t<_To>(*)[]>;
+
+    template<typename _From, typename _To>
       concept __convertible_to_non_slicing = convertible_to<_From, _To>
-       && !(is_pointer_v<decay_t<_From>> && is_pointer_v<decay_t<_To>>
-           && __not_same_as<remove_pointer_t<decay_t<_From>>,
-                            remove_pointer_t<decay_t<_To>>>);
+       && !__uses_nonqualification_pointer_conversion<decay_t<_From>,
+                                                      decay_t<_To>>;
 
     template<typename _Tp>
       concept __pair_like
diff --git a/libstdc++-v3/testsuite/std/ranges/subrange/1.cc b/libstdc++-v3/testsuite/std/ranges/subrange/1.cc
new file mode 100644 (file)
index 0000000..8a53261
--- /dev/null
@@ -0,0 +1,19 @@
+// { dg-options "-std=gnu++20" }
+// { dg-do run { target c++20 } }
+
+#include <ranges>
+
+void
+test01()
+{
+  // LWG 3470
+  int a[3] = {1,2,3};
+  int* b[3] = {&a[2], &a[0], &a[1]};
+  auto c = std::ranges::subrange<const int*const*>(b);
+}
+
+int
+main()
+{
+  test01();
+}