* [PATCH] libstdc++: Implement LWG 3470 change to ranges::subrange
@ 2021-10-19 18:29 Patrick Palka
2021-10-19 18:49 ` Jonathan Wakely
0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2021-10-19 18:29 UTC (permalink / raw)
To: gcc-patches; +Cc: libstdc++, Patrick Palka
Tested on x86_64-pc-linux-gnu, does this look OK for trunk and branches?
libstdc++-v3/ChangeLog:
* include/bits/ranges_util.h
(__detail::__uses_nonqualification_pointer_conversion): Define
and use it ...
(__convertible_to_nonslicing): ... here, as per LWG 3470.
* testsuite/std/ranges/subrange/1.cc: New test.
---
libstdc++-v3/include/bits/ranges_util.h | 13 +++++++++----
.../testsuite/std/ranges/subrange/1.cc | 19 +++++++++++++++++++
2 files changed, 28 insertions(+), 4 deletions(-)
create mode 100644 libstdc++-v3/testsuite/std/ranges/subrange/1.cc
diff --git a/libstdc++-v3/include/bits/ranges_util.h b/libstdc++-v3/include/bits/ranges_util.h
index 7e7b958d274..765848e327d 100644
--- a/libstdc++-v3/include/bits/ranges_util.h
+++ b/libstdc++-v3/include/bits/ranges_util.h
@@ -184,11 +184,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>>
- && __different_from<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
index 00000000000..8a53261c78c
--- /dev/null
+++ b/libstdc++-v3/testsuite/std/ranges/subrange/1.cc
@@ -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();
+}
--
2.33.1.711.g9d530dc002
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] libstdc++: Implement LWG 3470 change to ranges::subrange
2021-10-19 18:29 [PATCH] libstdc++: Implement LWG 3470 change to ranges::subrange Patrick Palka
@ 2021-10-19 18:49 ` Jonathan Wakely
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2021-10-19 18:49 UTC (permalink / raw)
To: Patrick Palka; +Cc: gcc-patches, libstdc++
On Tue, 19 Oct 2021, 19:30 Patrick Palka via Libstdc++, <
libstdc++@gcc.gnu.org> wrote:
> Tested on x86_64-pc-linux-gnu, does this look OK for trunk and branches?
>
Yes, thanks.
> libstdc++-v3/ChangeLog:
>
> * include/bits/ranges_util.h
> (__detail::__uses_nonqualification_pointer_conversion): Define
> and use it ...
> (__convertible_to_nonslicing): ... here, as per LWG 3470.
> * testsuite/std/ranges/subrange/1.cc: New test.
> ---
> libstdc++-v3/include/bits/ranges_util.h | 13 +++++++++----
> .../testsuite/std/ranges/subrange/1.cc | 19 +++++++++++++++++++
> 2 files changed, 28 insertions(+), 4 deletions(-)
> create mode 100644 libstdc++-v3/testsuite/std/ranges/subrange/1.cc
>
> diff --git a/libstdc++-v3/include/bits/ranges_util.h
> b/libstdc++-v3/include/bits/ranges_util.h
> index 7e7b958d274..765848e327d 100644
> --- a/libstdc++-v3/include/bits/ranges_util.h
> +++ b/libstdc++-v3/include/bits/ranges_util.h
> @@ -184,11 +184,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>>
> - && __different_from<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
> index 00000000000..8a53261c78c
> --- /dev/null
> +++ b/libstdc++-v3/testsuite/std/ranges/subrange/1.cc
> @@ -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();
> +}
> --
> 2.33.1.711.g9d530dc002
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-10-19 18:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-19 18:29 [PATCH] libstdc++: Implement LWG 3470 change to ranges::subrange Patrick Palka
2021-10-19 18:49 ` Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).