[committed] libstdc++: Add const to hash>::operator() [PR109165]

2023-03-17 Thread Jonathan Wakely via Gcc-patches
Tested x86_64-linux. Pushed to trunk. gcc-12 backport needed too.

-- >8 --

libstdc++-v3/ChangeLog:

PR libstdc++/109165
* include/std/coroutine (hash<>::operator()): Add const.
* testsuite/18_support/coroutines/hash.cc: New test.
---
 libstdc++-v3/include/std/coroutine|  2 +-
 .../testsuite/18_support/coroutines/hash.cc   | 22 +++
 2 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 libstdc++-v3/testsuite/18_support/coroutines/hash.cc

diff --git a/libstdc++-v3/include/std/coroutine 
b/libstdc++-v3/include/std/coroutine
index f6e65566f10..b0ca18949db 100644
--- a/libstdc++-v3/include/std/coroutine
+++ b/libstdc++-v3/include/std/coroutine
@@ -345,7 +345,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 struct hash>
 {
   size_t
-  operator()(const coroutine_handle<_Promise>& __h) noexcept
+  operator()(const coroutine_handle<_Promise>& __h) const noexcept
   {
return reinterpret_cast(__h.address());
   }
diff --git a/libstdc++-v3/testsuite/18_support/coroutines/hash.cc 
b/libstdc++-v3/testsuite/18_support/coroutines/hash.cc
new file mode 100644
index 000..68e5e640477
--- /dev/null
+++ b/libstdc++-v3/testsuite/18_support/coroutines/hash.cc
@@ -0,0 +1,22 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include 
+#include 
+
+void
+test01()
+{
+  std::hash h;
+  std::size_t v = h(std::noop_coroutine());
+
+  const auto& ch = h;
+  std::size_t v2 = h(std::noop_coroutine()); // PR libstdc++/109165
+
+  VERIFY( v2 == v );
+}
+
+int main()
+{
+  test01();
+}
-- 
2.39.2



Re: [committed] libstdc++: Add const to hash>::operator() [PR109165]

2023-03-17 Thread Nathaniel Shead via Gcc-patches
On Sat, Mar 18, 2023 at 7:36 AM Jonathan Wakely via Libstdc++
 wrote:
>
> Tested x86_64-linux. Pushed to trunk. gcc-12 backport needed too.
>
> -- >8 --
>
> libstdc++-v3/ChangeLog:
>
> PR libstdc++/109165
> * include/std/coroutine (hash<>::operator()): Add const.
> * testsuite/18_support/coroutines/hash.cc: New test.
> ---
>  libstdc++-v3/include/std/coroutine|  2 +-
>  .../testsuite/18_support/coroutines/hash.cc   | 22 +++
>  2 files changed, 23 insertions(+), 1 deletion(-)
>  create mode 100644 libstdc++-v3/testsuite/18_support/coroutines/hash.cc
>
> diff --git a/libstdc++-v3/include/std/coroutine 
> b/libstdc++-v3/include/std/coroutine
> index f6e65566f10..b0ca18949db 100644
> --- a/libstdc++-v3/include/std/coroutine
> +++ b/libstdc++-v3/include/std/coroutine
> @@ -345,7 +345,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>  struct hash>
>  {
>size_t
> -  operator()(const coroutine_handle<_Promise>& __h) noexcept
> +  operator()(const coroutine_handle<_Promise>& __h) const noexcept
>{
> return reinterpret_cast(__h.address());
>}
> diff --git a/libstdc++-v3/testsuite/18_support/coroutines/hash.cc 
> b/libstdc++-v3/testsuite/18_support/coroutines/hash.cc
> new file mode 100644
> index 000..68e5e640477
> --- /dev/null
> +++ b/libstdc++-v3/testsuite/18_support/coroutines/hash.cc
> @@ -0,0 +1,22 @@
> +// { dg-options "-std=gnu++2a" }
> +// { dg-do run { target c++2a } }
> +
> +#include 
> +#include 
> +
> +void
> +test01()
> +{
> +  std::hash h;
> +  std::size_t v = h(std::noop_coroutine());
> +
> +  const auto& ch = h;
> +  std::size_t v2 = h(std::noop_coroutine()); // PR libstdc++/109165

Is this supposed to be `std::size_t v2 = ch(...)`?

> +
> +  VERIFY( v2 == v );
> +}
> +
> +int main()
> +{
> +  test01();
> +}
> --
> 2.39.2
>


Re: [committed] libstdc++: Add const to hash>::operator() [PR109165]

2023-03-18 Thread Jonathan Wakely via Gcc-patches
On Sat, 18 Mar 2023 at 00:49, Nathaniel Shead wrote:

> On Sat, Mar 18, 2023 at 7:36 AM Jonathan Wakely via Libstdc++
>  wrote:
> >
> > Tested x86_64-linux. Pushed to trunk. gcc-12 backport needed too.
> >
> > -- >8 --
> >
> > libstdc++-v3/ChangeLog:
> >
> > PR libstdc++/109165
> > * include/std/coroutine (hash<>::operator()): Add const.
> > * testsuite/18_support/coroutines/hash.cc: New test.
> > ---
> >  libstdc++-v3/include/std/coroutine|  2 +-
> >  .../testsuite/18_support/coroutines/hash.cc   | 22 +++
> >  2 files changed, 23 insertions(+), 1 deletion(-)
> >  create mode 100644 libstdc++-v3/testsuite/18_support/coroutines/hash.cc
> >
> > diff --git a/libstdc++-v3/include/std/coroutine
> b/libstdc++-v3/include/std/coroutine
> > index f6e65566f10..b0ca18949db 100644
> > --- a/libstdc++-v3/include/std/coroutine
> > +++ b/libstdc++-v3/include/std/coroutine
> > @@ -345,7 +345,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >  struct hash>
> >  {
> >size_t
> > -  operator()(const coroutine_handle<_Promise>& __h) noexcept
> > +  operator()(const coroutine_handle<_Promise>& __h) const noexcept
> >{
> > return reinterpret_cast(__h.address());
> >}
> > diff --git a/libstdc++-v3/testsuite/18_support/coroutines/hash.cc
> b/libstdc++-v3/testsuite/18_support/coroutines/hash.cc
> > new file mode 100644
> > index 000..68e5e640477
> > --- /dev/null
> > +++ b/libstdc++-v3/testsuite/18_support/coroutines/hash.cc
> > @@ -0,0 +1,22 @@
> > +// { dg-options "-std=gnu++2a" }
> > +// { dg-do run { target c++2a } }
> > +
> > +#include 
> > +#include 
> > +
> > +void
> > +test01()
> > +{
> > +  std::hash h;
> > +  std::size_t v = h(std::noop_coroutine());
> > +
> > +  const auto& ch = h;
> > +  std::size_t v2 = h(std::noop_coroutine()); // PR libstdc++/109165
>
> Is this supposed to be `std::size_t v2 = ch(...)`?
>
>
Doh! Yes, thanks. Fixed by the attached change.

Tested x86_64-linux, pushed to trunk.
commit 9b83d4755a7da02f25788fce14bec949e7045f8f
Author: Jonathan Wakely 
Date:   Fri Mar 17 11:39:55 2023

libstdc++: Fix test for hash>::operator() [PR109165]

libstdc++-v3/ChangeLog:

PR libstdc++/109165
* testsuite/18_support/coroutines/hash.cc: Use const object
in second call.

diff --git a/libstdc++-v3/testsuite/18_support/coroutines/hash.cc 
b/libstdc++-v3/testsuite/18_support/coroutines/hash.cc
index 68e5e640477..81b68f8246a 100644
--- a/libstdc++-v3/testsuite/18_support/coroutines/hash.cc
+++ b/libstdc++-v3/testsuite/18_support/coroutines/hash.cc
@@ -7,11 +7,12 @@
 void
 test01()
 {
+  auto coro = std::noop_coroutine();
   std::hash h;
-  std::size_t v = h(std::noop_coroutine());
+  std::size_t v = h(coro);
 
   const auto& ch = h;
-  std::size_t v2 = h(std::noop_coroutine()); // PR libstdc++/109165
+  std::size_t v2 = ch(coro); // PR libstdc++/109165
 
   VERIFY( v2 == v );
 }