]> git.ipfire.org Git - people/ms/gcc.git/commitdiff
libstdc++: Add const to hash<coroutine_handle<P>>::operator() [PR109165]
authorJonathan Wakely <jwakely@redhat.com>
Fri, 17 Mar 2023 11:39:55 +0000 (11:39 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 20 Mar 2023 09:36:44 +0000 (09:36 +0000)
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
libstdc++-v3/testsuite/18_support/coroutines/hash.cc [new file with mode: 0644]

index f4189c7e3fcf11de326dc952d9404936561d8ea8..47f0ab95c37365b29d5df1f14ac47fca8b9f5ad1 100644 (file)
@@ -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 (file)
index 0000000..81b68f8
--- /dev/null
@@ -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();
+}