aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2023-03-17 11:39:55 +0000
committerJonathan Wakely <jwakely@redhat.com>2023-03-17 20:34:52 +0000
commitc48be8298c27143c1a684c0cb9689c88d16f4b49 (patch)
tree8cd28db54f05f371d036e20118087ea01232cc24
parentae7190e345a8d80310835cb83b3b41ef2aeb0d37 (diff)
downloadgcc-c48be8298c27143c1a684c0cb9689c88d16f4b49.zip
gcc-c48be8298c27143c1a684c0cb9689c88d16f4b49.tar.gz
gcc-c48be8298c27143c1a684c0cb9689c88d16f4b49.tar.bz2
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.
-rw-r--r--libstdc++-v3/include/std/coroutine2
-rw-r--r--libstdc++-v3/testsuite/18_support/coroutines/hash.cc22
2 files changed, 23 insertions, 1 deletions
diff --git a/libstdc++-v3/include/std/coroutine b/libstdc++-v3/include/std/coroutine
index f6e6556..b0ca189 100644
--- a/libstdc++-v3/include/std/coroutine
+++ b/libstdc++-v3/include/std/coroutine
@@ -345,7 +345,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 0000000..68e5e64
--- /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 <coroutine>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ std::hash<std::noop_coroutine_handle> 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();
+}