public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r13-8067] libstdc++: Fix std::hash<std::stacktrace> [PR112348]
Date: Tue, 14 Nov 2023 22:40:10 +0000 (GMT)	[thread overview]
Message-ID: <20231114224010.5988F3858417@sourceware.org> (raw)

https://gcc.gnu.org/g:16635b89f36c07b9e06c48a93d1bfafa93178328

commit r13-8067-g16635b89f36c07b9e06c48a93d1bfafa93178328
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Nov 14 22:36:31 2023 +0000

    libstdc++: Fix std::hash<std::stacktrace> [PR112348]
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/112348
            * include/std/stacktrace (hash<basic_stacktrace<Alloc>>): Fix
            type of hash function for entries.
            * testsuite/19_diagnostics/stacktrace/hash.cc: New test.
    
    (cherry picked from commit 6f2fc42d9e52e8322e718e0154cd235d00906f99)

Diff:
---
 libstdc++-v3/include/std/stacktrace                |  2 +-
 .../testsuite/19_diagnostics/stacktrace/hash.cc    | 23 ++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/stacktrace b/libstdc++-v3/include/std/stacktrace
index 346c7b14142..96702935433 100644
--- a/libstdc++-v3/include/std/stacktrace
+++ b/libstdc++-v3/include/std/stacktrace
@@ -790,7 +790,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..cf18476f2a7
--- /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 <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();
+}

                 reply	other threads:[~2023-11-14 22:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231114224010.5988F3858417@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).