From a97c08ea530dadf366022b5c3e5aab21d34a61bd Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Tue, 14 Nov 2023 22:36:31 +0000 Subject: [PATCH] libstdc++: Fix std::hash [PR112348] libstdc++-v3/ChangeLog: PR libstdc++/112348 * include/std/stacktrace (hash>): Fix type of hash function for entries. * testsuite/19_diagnostics/stacktrace/hash.cc: New test. (cherry picked from commit 6f2fc42d9e52e8322e718e0154cd235d00906f99) --- libstdc++-v3/include/std/stacktrace | 2 +- .../19_diagnostics/stacktrace/hash.cc | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 libstdc++-v3/testsuite/19_diagnostics/stacktrace/hash.cc diff --git a/libstdc++-v3/include/std/stacktrace b/libstdc++-v3/include/std/stacktrace index d46c05b3cd94..eb3765133586 100644 --- a/libstdc++-v3/include/std/stacktrace +++ b/libstdc++-v3/include/std/stacktrace @@ -782,7 +782,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION size_t operator()(const basic_stacktrace<_Allocator>& __st) const noexcept { - hash __h; + hash __h; size_t __val = _Hash_impl::hash(__st.size()); for (const auto& __f : __st) __val = _Hash_impl::__hash_combine(__h(__f), __val); diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/hash.cc b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/hash.cc new file mode 100644 index 000000000000..cf18476f2a7f --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/hash.cc @@ -0,0 +1,23 @@ +// { dg-options "-std=gnu++23 -lstdc++_libbacktrace" } +// { dg-do run { target c++23 } } +// { dg-require-effective-target stacktrace } + +#include +#include +#include + +void +test_hash() +{ + using Alloc = __gnu_test::uneq_allocator; + using S = std::basic_stacktrace; + S s; + std::size_t h = std::hash()(s); + std::size_t h2 = std::hash()(S::current()); + VERIFY( h != h2 ); +} + +int main() +{ + test_hash(); +} -- 2.47.2