public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r12-9296] libstdc++: Add const to hash<coroutine_handle<P>>::operator() [PR109165]
Date: Mon, 20 Mar 2023 11:54:36 +0000 (GMT)	[thread overview]
Message-ID: <20230320115436.276783858C74@sourceware.org> (raw)

https://gcc.gnu.org/g:2a9e6f58c4d9d63dde6c4d53d10f686bf71fb435

commit r12-9296-g2a9e6f58c4d9d63dde6c4d53d10f686bf71fb435
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Mar 17 11:39:55 2023 +0000

    libstdc++: Add const to hash<coroutine_handle<P>>::operator() [PR109165]
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/109165
            * include/std/coroutine (hash<>::operator()): Add const.
            * testsuite/18_support/coroutines/hash.cc: New test.

Diff:
---
 libstdc++-v3/include/std/coroutine                 |  2 +-
 .../testsuite/18_support/coroutines/hash.cc        | 23 ++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/coroutine b/libstdc++-v3/include/std/coroutine
index f4189c7e3fc..47f0ab95c37 100644
--- a/libstdc++-v3/include/std/coroutine
+++ b/libstdc++-v3/include/std/coroutine
@@ -350,7 +350,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct hash<coroutine_handle<_Promise>>
     {
       size_t
-      operator()(const coroutine_handle<_Promise>& __h) noexcept
+      operator()(const coroutine_handle<_Promise>& __h) const noexcept
       {
 	return reinterpret_cast<size_t>(__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 00000000000..81b68f8246a
--- /dev/null
+++ b/libstdc++-v3/testsuite/18_support/coroutines/hash.cc
@@ -0,0 +1,23 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <coroutine>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  auto coro = std::noop_coroutine();
+  std::hash<std::noop_coroutine_handle> h;
+  std::size_t v = h(coro);
+
+  const auto& ch = h;
+  std::size_t v2 = ch(coro); // PR libstdc++/109165
+
+  VERIFY( v2 == v );
+}
+
+int main()
+{
+  test01();
+}

                 reply	other threads:[~2023-03-20 11:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230320115436.276783858C74@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).