public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libstdc++: Fix typo in views::as_const's operator() [PR109525]
@ 2023-04-17  3:45 Patrick Palka
  2023-04-17  7:23 ` Jonathan Wakely
  0 siblings, 1 reply; 4+ messages in thread
From: Patrick Palka @ 2023-04-17  3:45 UTC (permalink / raw)
  To: gcc-patches; +Cc: libstdc++, Patrick Palka

	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.
---
 libstdc++-v3/include/std/ranges               |  2 +-
 .../std/ranges/adaptors/as_const/1.cc         | 37 ++++++++++++-------
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 283d757faa4..1714f3fb16c 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<const element_type&>
 			  (std::forward<_Range>(__r).base()));
 	else if constexpr (is_lvalue_reference_v<_Range>
-			   && constant_range<_Tp>
+			   && constant_range<const _Tp>
 			   && !view<_Tp>)
 	  return ref_view(static_cast<const _Tp&>(__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 d04645f047e..ac1be7440e4 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 <algorithm>
 #include <span>
 #include <utility>
+#include <vector>
 #include <testsuite_hooks.h>
 #include <testsuite_iterators.h>
 
@@ -36,29 +37,37 @@ test01()
 constexpr bool
 test02()
 {
-  std::same_as<ranges::empty_view<const int>> auto v1
-    = views::empty<int> | views::as_const;
-
   int x[] = {1, 2, 3};
-  std::same_as<ranges::as_const_view<ranges::ref_view<int[3]>>> auto v2
-    = x | views::as_const;
-  std::same_as<ranges::ref_view<const int[3]>> auto v3
-    = std::as_const(x) | views::as_const;
-  std::same_as<ranges::ref_view<const int[3]>> auto v4
-    = std::as_const(x) | views::all | views::as_const;
-  std::same_as<std::span<const int>> auto v5
-    = std::span{x, x+3} | views::as_const;
-
-  std::same_as<ranges::as_const_view<ranges::chunk_view<ranges::ref_view<int[3]>>>> auto v6
-     = x | views::chunk(2) | views::as_const;
+  std::same_as<ranges::empty_view<const int>>
+    auto v1 = views::empty<int> | views::as_const;
+  std::same_as<ranges::ref_view<const int[3]>>
+    auto v2 = x | views::as_const;
+  std::same_as<ranges::ref_view<const int[3]>>
+    auto v3 = std::as_const(x) | views::as_const;
+  std::same_as<ranges::ref_view<const int[3]>>
+    auto v4 = std::as_const(x) | views::all | views::as_const;
+  std::same_as<std::span<const int>>
+    auto v5 = std::span{x, x+3} | views::as_const;
+  std::same_as<ranges::as_const_view<ranges::chunk_view<ranges::ref_view<int[3]>>>>
+    auto v6 = x | views::chunk(2) | views::as_const;
   VERIFY( v6.size() == 2 );
 
   return true;
 }
 
+void
+test03()
+{
+  // PR libstdc++/109525
+  std::vector<int> v;
+  std::same_as<ranges::ref_view<const std::vector<int>>>
+    auto r = views::as_const(v);
+}
+
 int
 main()
 {
   static_assert(test01());
   static_assert(test02());
+  test03();
 }
-- 
2.40.0.335.g9857273be0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] libstdc++: Fix typo in views::as_const's operator() [PR109525]
  2023-04-17  3:45 [PATCH] libstdc++: Fix typo in views::as_const's operator() [PR109525] Patrick Palka
@ 2023-04-17  7:23 ` Jonathan Wakely
  2023-04-18  8:57   ` Jonathan Wakely
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Wakely @ 2023-04-17  7:23 UTC (permalink / raw)
  To: Patrick Palka; +Cc: gcc-patches, libstdc++

[-- Attachment #1: Type: text/plain, Size: 3552 bytes --]

OK

On Mon, 17 Apr 2023, 05:46 Patrick Palka via Libstdc++, <
libstdc++@gcc.gnu.org> wrote:

>         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.
> ---
>  libstdc++-v3/include/std/ranges               |  2 +-
>  .../std/ranges/adaptors/as_const/1.cc         | 37 ++++++++++++-------
>  2 files changed, 24 insertions(+), 15 deletions(-)
>
> diff --git a/libstdc++-v3/include/std/ranges
> b/libstdc++-v3/include/std/ranges
> index 283d757faa4..1714f3fb16c 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<const element_type&>
>                           (std::forward<_Range>(__r).base()));
>         else if constexpr (is_lvalue_reference_v<_Range>
> -                          && constant_range<_Tp>
> +                          && constant_range<const _Tp>
>                            && !view<_Tp>)
>           return ref_view(static_cast<const _Tp&>(__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 d04645f047e..ac1be7440e4 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 <algorithm>
>  #include <span>
>  #include <utility>
> +#include <vector>
>  #include <testsuite_hooks.h>
>  #include <testsuite_iterators.h>
>
> @@ -36,29 +37,37 @@ test01()
>  constexpr bool
>  test02()
>  {
> -  std::same_as<ranges::empty_view<const int>> auto v1
> -    = views::empty<int> | views::as_const;
> -
>    int x[] = {1, 2, 3};
> -  std::same_as<ranges::as_const_view<ranges::ref_view<int[3]>>> auto v2
> -    = x | views::as_const;
> -  std::same_as<ranges::ref_view<const int[3]>> auto v3
> -    = std::as_const(x) | views::as_const;
> -  std::same_as<ranges::ref_view<const int[3]>> auto v4
> -    = std::as_const(x) | views::all | views::as_const;
> -  std::same_as<std::span<const int>> auto v5
> -    = std::span{x, x+3} | views::as_const;
> -
> -
> std::same_as<ranges::as_const_view<ranges::chunk_view<ranges::ref_view<int[3]>>>>
> auto v6
> -     = x | views::chunk(2) | views::as_const;
> +  std::same_as<ranges::empty_view<const int>>
> +    auto v1 = views::empty<int> | views::as_const;
> +  std::same_as<ranges::ref_view<const int[3]>>
> +    auto v2 = x | views::as_const;
> +  std::same_as<ranges::ref_view<const int[3]>>
> +    auto v3 = std::as_const(x) | views::as_const;
> +  std::same_as<ranges::ref_view<const int[3]>>
> +    auto v4 = std::as_const(x) | views::all | views::as_const;
> +  std::same_as<std::span<const int>>
> +    auto v5 = std::span{x, x+3} | views::as_const;
> +
> std::same_as<ranges::as_const_view<ranges::chunk_view<ranges::ref_view<int[3]>>>>
> +    auto v6 = x | views::chunk(2) | views::as_const;
>    VERIFY( v6.size() == 2 );
>
>    return true;
>  }
>
> +void
> +test03()
> +{
> +  // PR libstdc++/109525
> +  std::vector<int> v;
> +  std::same_as<ranges::ref_view<const std::vector<int>>>
> +    auto r = views::as_const(v);
> +}
> +
>  int
>  main()
>  {
>    static_assert(test01());
>    static_assert(test02());
> +  test03();
>  }
> --
> 2.40.0.335.g9857273be0
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] libstdc++: Fix typo in views::as_const's operator() [PR109525]
  2023-04-17  7:23 ` Jonathan Wakely
@ 2023-04-18  8:57   ` Jonathan Wakely
  2023-04-18  9:00     ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Wakely @ 2023-04-18  8:57 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: Patrick Palka, gcc-patches, libstdc++, Jakub Jelinek

On Mon, 17 Apr 2023 at 08:23, Jonathan Wakely via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> OK

I'd like RM approval to push this C++23-only change to gcc-13 as well as trunk.


>
> On Mon, 17 Apr 2023, 05:46 Patrick Palka via Libstdc++, <
> libstdc++@gcc.gnu.org> wrote:
>
> >         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.
> > ---
> >  libstdc++-v3/include/std/ranges               |  2 +-
> >  .../std/ranges/adaptors/as_const/1.cc         | 37 ++++++++++++-------
> >  2 files changed, 24 insertions(+), 15 deletions(-)
> >
> > diff --git a/libstdc++-v3/include/std/ranges
> > b/libstdc++-v3/include/std/ranges
> > index 283d757faa4..1714f3fb16c 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<const element_type&>
> >                           (std::forward<_Range>(__r).base()));
> >         else if constexpr (is_lvalue_reference_v<_Range>
> > -                          && constant_range<_Tp>
> > +                          && constant_range<const _Tp>
> >                            && !view<_Tp>)
> >           return ref_view(static_cast<const _Tp&>(__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 d04645f047e..ac1be7440e4 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 <algorithm>
> >  #include <span>
> >  #include <utility>
> > +#include <vector>
> >  #include <testsuite_hooks.h>
> >  #include <testsuite_iterators.h>
> >
> > @@ -36,29 +37,37 @@ test01()
> >  constexpr bool
> >  test02()
> >  {
> > -  std::same_as<ranges::empty_view<const int>> auto v1
> > -    = views::empty<int> | views::as_const;
> > -
> >    int x[] = {1, 2, 3};
> > -  std::same_as<ranges::as_const_view<ranges::ref_view<int[3]>>> auto v2
> > -    = x | views::as_const;
> > -  std::same_as<ranges::ref_view<const int[3]>> auto v3
> > -    = std::as_const(x) | views::as_const;
> > -  std::same_as<ranges::ref_view<const int[3]>> auto v4
> > -    = std::as_const(x) | views::all | views::as_const;
> > -  std::same_as<std::span<const int>> auto v5
> > -    = std::span{x, x+3} | views::as_const;
> > -
> > -
> > std::same_as<ranges::as_const_view<ranges::chunk_view<ranges::ref_view<int[3]>>>>
> > auto v6
> > -     = x | views::chunk(2) | views::as_const;
> > +  std::same_as<ranges::empty_view<const int>>
> > +    auto v1 = views::empty<int> | views::as_const;
> > +  std::same_as<ranges::ref_view<const int[3]>>
> > +    auto v2 = x | views::as_const;
> > +  std::same_as<ranges::ref_view<const int[3]>>
> > +    auto v3 = std::as_const(x) | views::as_const;
> > +  std::same_as<ranges::ref_view<const int[3]>>
> > +    auto v4 = std::as_const(x) | views::all | views::as_const;
> > +  std::same_as<std::span<const int>>
> > +    auto v5 = std::span{x, x+3} | views::as_const;
> > +
> > std::same_as<ranges::as_const_view<ranges::chunk_view<ranges::ref_view<int[3]>>>>
> > +    auto v6 = x | views::chunk(2) | views::as_const;
> >    VERIFY( v6.size() == 2 );
> >
> >    return true;
> >  }
> >
> > +void
> > +test03()
> > +{
> > +  // PR libstdc++/109525
> > +  std::vector<int> v;
> > +  std::same_as<ranges::ref_view<const std::vector<int>>>
> > +    auto r = views::as_const(v);
> > +}
> > +
> >  int
> >  main()
> >  {
> >    static_assert(test01());
> >    static_assert(test02());
> > +  test03();
> >  }
> > --
> > 2.40.0.335.g9857273be0
> >
> >
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] libstdc++: Fix typo in views::as_const's operator() [PR109525]
  2023-04-18  8:57   ` Jonathan Wakely
@ 2023-04-18  9:00     ` Jakub Jelinek
  0 siblings, 0 replies; 4+ messages in thread
From: Jakub Jelinek @ 2023-04-18  9:00 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: Jonathan Wakely, Patrick Palka, gcc-patches, libstdc++

On Tue, Apr 18, 2023 at 09:57:35AM +0100, Jonathan Wakely wrote:
> On Mon, 17 Apr 2023 at 08:23, Jonathan Wakely via Libstdc++
> <libstdc++@gcc.gnu.org> wrote:
> >
> > OK
> 
> I'd like RM approval to push this C++23-only change to gcc-13 as well as trunk.

Ok.

	Jakub


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-04-18  9:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-17  3:45 [PATCH] libstdc++: Fix typo in views::as_const's operator() [PR109525] Patrick Palka
2023-04-17  7:23 ` Jonathan Wakely
2023-04-18  8:57   ` Jonathan Wakely
2023-04-18  9:00     ` Jakub Jelinek

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).