public inbox for gcc-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 r12-6827] libstdc++: Restore support for unordered_map<const T,  ...> [PR104174]
Date: Sun, 23 Jan 2022 22:49:43 +0000 (GMT)	[thread overview]
Message-ID: <20220123224943.99E00385842C@sourceware.org> (raw)

https://gcc.gnu.org/g:084680db9af077ca37c5523a58b6c11e090e7335

commit r12-6827-g084680db9af077ca37c5523a58b6c11e090e7335
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Sat Jan 22 00:35:45 2022 +0000

    libstdc++: Restore support for unordered_map<const T, ...> [PR104174]
    
    I broke this unintentionally in r12-4259.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/104174
            * include/bits/hashtable_policy.h (_Map_base): Add partial
            specialization for maps with const key types.
            * testsuite/23_containers/unordered_map/104174.cc: New test.

Diff:
---
 libstdc++-v3/include/bits/hashtable_policy.h                 | 11 +++++++++++
 libstdc++-v3/testsuite/23_containers/unordered_map/104174.cc |  4 ++++
 2 files changed, 15 insertions(+)

diff --git a/libstdc++-v3/include/bits/hashtable_policy.h b/libstdc++-v3/include/bits/hashtable_policy.h
index 3b60eb9ae72..0f0b0f9ea51 100644
--- a/libstdc++-v3/include/bits/hashtable_policy.h
+++ b/libstdc++-v3/include/bits/hashtable_policy.h
@@ -812,6 +812,17 @@ namespace __detail
       return __pos->second;
     }
 
+  // Partial specialization for unordered_map<const T, U>, see PR 104174.
+  template<typename _Key, typename _Val, typename _Alloc, typename _Equal,
+	   typename _Hash, typename _RangeHash, typename _Unused,
+	   typename _RehashPolicy, typename _Traits, bool __uniq>
+    struct _Map_base<const _Key, pair<const _Key, _Val>,
+		     _Alloc, _Select1st, _Equal, _Hash,
+		     _RangeHash, _Unused, _RehashPolicy, _Traits, __uniq>
+    : _Map_base<_Key, pair<const _Key, _Val>, _Alloc, _Select1st, _Equal, _Hash,
+		_RangeHash, _Unused, _RehashPolicy, _Traits, __uniq>
+    { };
+
   /**
    *  Primary class template _Insert_base.
    *
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/104174.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/104174.cc
new file mode 100644
index 00000000000..4007425bf74
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/unordered_map/104174.cc
@@ -0,0 +1,4 @@
+// { dg-do compile { target c++11 } }
+// PR libstdc++/104174 unordered_map<const T, U, H> fails
+#include <unordered_map>
+std::unordered_map<const int, int, std::hash<int>> m;


                 reply	other threads:[~2022-01-23 22:49 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=20220123224943.99E00385842C@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).