* [committed] libstdc++: Fix std::hash<std::stacktrace> [PR112348]
@ 2023-11-14 22:32 Jonathan Wakely
0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2023-11-14 22:32 UTC (permalink / raw)
To: libstdc++, gcc-patches
Tested x86_64-linux. Pushed to trunk. Backports needed too.
-- >8 --
libstdc++-v3/ChangeLog:
PR libstdc++/112348
* include/std/stacktrace (hash<basic_stacktrace<Alloc>>): Fix
type of hash functio nfor entries.
* testsuite/19_diagnostics/stacktrace/hash.cc: New test.
---
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 da0e48d3532..9a0d0b16068 100644
--- a/libstdc++-v3/include/std/stacktrace
+++ b/libstdc++-v3/include/std/stacktrace
@@ -797,7 +797,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
size_t
operator()(const basic_stacktrace<_Allocator>& __st) const noexcept
{
- hash<stacktrace_entry::native_handle_type> __h;
+ hash<stacktrace_entry> __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 00000000000..88831efd687
--- /dev/null
+++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/hash.cc
@@ -0,0 +1,23 @@
+// { dg-options "-lstdc++exp" }
+// { dg-do run { target c++23 } }
+// { dg-require-effective-target stacktrace }
+
+#include <stacktrace>
+#include <testsuite_allocator.h>
+#include <testsuite_hooks.h>
+
+void
+test_hash()
+{
+ using Alloc = __gnu_test::uneq_allocator<std::stacktrace_entry>;
+ using S = std::basic_stacktrace<Alloc>;
+ S s;
+ std::size_t h = std::hash<S>()(s);
+ std::size_t h2 = std::hash<S>()(S::current());
+ VERIFY( h != h2 );
+}
+
+int main()
+{
+ test_hash();
+}
--
2.41.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-11-14 22:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-14 22:32 [committed] libstdc++: Fix std::hash<std::stacktrace> [PR112348] Jonathan Wakely
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).