From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 276783858C74; Mon, 20 Mar 2023 11:54:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 276783858C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679313276; bh=HFfB9wHRtWc7l7pp9rntequkSWqQnhRgqbO8SvrVrcI=; h=From:To:Subject:Date:From; b=UXqwe8DnF3d4R8B3L8VvDaIuuvFXQFSb70jxW8tqfrC3z8iF4U+hZo/IXm3z6du8a pI0/x6Z47lb5F65oDjP1NQi6NQsQfqpLRXq7c0mVozdT0AfwO4nN7G5l6LXcPHjMZy 3dPQc0Y7xwApdhgAFGxRAMAuCOTC+JA6ELOuzpec= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-9296] libstdc++: Add const to hash>::operator() [PR109165] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 9ccf471f8cc7341984f6613247f01d8ecfcb7ad5 X-Git-Newrev: 2a9e6f58c4d9d63dde6c4d53d10f686bf71fb435 Message-Id: <20230320115436.276783858C74@sourceware.org> Date: Mon, 20 Mar 2023 11:54:36 +0000 (GMT) List-Id: https://gcc.gnu.org/g:2a9e6f58c4d9d63dde6c4d53d10f686bf71fb435 commit r12-9296-g2a9e6f58c4d9d63dde6c4d53d10f686bf71fb435 Author: Jonathan Wakely Date: Fri Mar 17 11:39:55 2023 +0000 libstdc++: Add const to hash>::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> { 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 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 +#include + +void +test01() +{ + auto coro = std::noop_coroutine(); + std::hash 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(); +}