get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/2226685/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2226685,
    "url": "http://patchwork.ozlabs.org/api/patches/2226685/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/gcc/patch/bmm.hhuo67grsc.gcc.gcc-TEST.fdumont.47.1.1@forge-stage.sourceware.org/",
    "project": {
        "id": 17,
        "url": "http://patchwork.ozlabs.org/api/projects/17/?format=api",
        "name": "GNU Compiler Collection",
        "link_name": "gcc",
        "list_id": "gcc-patches.gcc.gnu.org",
        "list_email": "gcc-patches@gcc.gnu.org",
        "web_url": null,
        "scm_url": null,
        "webscm_url": null,
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<bmm.hhuo67grsc.gcc.gcc-TEST.fdumont.47.1.1@forge-stage.sourceware.org>",
    "list_archive_url": null,
    "date": "2026-04-22T18:14:32",
    "name": "[v1,1/2] libstdc++: Make debug iterator pointer sequence const [PR116369]",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "16fd7adae92fa35beaaf0c582d98c42768b46ff6",
    "submitter": {
        "id": 93220,
        "url": "http://patchwork.ozlabs.org/api/people/93220/?format=api",
        "name": "François Dumont via Sourceware Forge",
        "email": "forge-bot+fdumont@forge-stage.sourceware.org"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/gcc/patch/bmm.hhuo67grsc.gcc.gcc-TEST.fdumont.47.1.1@forge-stage.sourceware.org/mbox/",
    "series": [
        {
            "id": 501071,
            "url": "http://patchwork.ozlabs.org/api/series/501071/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/gcc/list/?series=501071",
            "date": "2026-04-22T18:14:31",
            "name": "libstdc++: Make debug iterator pointer sequence const [PR116369]",
            "version": 1,
            "mbox": "http://patchwork.ozlabs.org/series/501071/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2226685/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2226685/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>",
        "X-Original-To": [
            "incoming@patchwork.ozlabs.org",
            "gcc-patches@gcc.gnu.org"
        ],
        "Delivered-To": [
            "patchwork-incoming@legolas.ozlabs.org",
            "gcc-patches@gcc.gnu.org"
        ],
        "Authentication-Results": [
            "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)",
            "sourceware.org; dmarc=none (p=none dis=none)\n header.from=forge-stage.sourceware.org",
            "sourceware.org;\n spf=pass smtp.mailfrom=forge-stage.sourceware.org",
            "server2.sourceware.org;\n arc=none smtp.remote-ip=38.145.34.39"
        ],
        "Received": [
            "from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g176V73WDz1yGs\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 04:29:22 +1000 (AEST)",
            "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id F19534360B90\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 18:29:20 +0000 (GMT)",
            "from forge-stage.sourceware.org (vm08.sourceware.org [38.145.34.39])\n by sourceware.org (Postfix) with ESMTPS id 50F0D4CD2027\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 18:16:19 +0000 (GMT)",
            "from forge-stage.sourceware.org (localhost [IPv6:::1])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256)\n (No client certificate requested)\n by forge-stage.sourceware.org (Postfix) with ESMTPS id 9866243430\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 18:16:03 +0000 (UTC)"
        ],
        "DKIM-Filter": [
            "OpenDKIM Filter v2.11.0 sourceware.org F19534360B90",
            "OpenDKIM Filter v2.11.0 sourceware.org 50F0D4CD2027"
        ],
        "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org 50F0D4CD2027",
        "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org 50F0D4CD2027",
        "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776881779; cv=none;\n b=GRTv+oZXPUcYaLnVRQjeYdPoujNGQgZzEtdagHVk5OQFE/wnymYUrrq/2Ry99um3Mw/6jwdZQsJ0ADIINbYqFjIWkLBYCkWOFHaCGZPLCX0mbmIuHZOGmzzrPU4OnmsaIJvKqHBHsyRne4LKu1Q7BNKhXfX+PLO3u9pyIG2q/to=",
        "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776881779; c=relaxed/simple;\n bh=dGBZQt+xu+7746a1xYugraMDkLcvqF07B91zKnuImVA=;\n h=From:Date:Subject:MIME-Version:To:Message-ID;\n b=o++n4GI91NNvjeFANXR5wK0N4UDEEf1/1UYieagj1msDyu0tPQPFdTwY1HSi3FSi+c4inksZGTC1LpeZGdfZQ52XcrsnFSn1V+Z/p9UsVsAIKuFXXKSv9x5+MJI/SQ2gVTN9nkLmTQC7ie/8aPcJZeQmgANOflT+ewxSEx9xOWU=",
        "ARC-Authentication-Results": "i=1; server2.sourceware.org",
        "From": "=?utf-8?q?Fran=C3=A7ois_Dumont_via_Sourceware_Forge?=\n <forge-bot+fdumont@forge-stage.sourceware.org>",
        "Date": "Wed, 22 Apr 2026 18:14:32 +0000",
        "Subject": "[PATCH v1 1/2] libstdc++: Make debug iterator pointer sequence const\n [PR116369]",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "To": "gcc-patches mailing list <gcc-patches@gcc.gnu.org>",
        "Message-ID": "\n <bmm.hhuo67grsc.gcc.gcc-TEST.fdumont.47.1.1@forge-stage.sourceware.org>",
        "X-Mailer": "batrachomyomachia",
        "X-Pull-Request-Organization": "gcc",
        "X-Pull-Request-Repository": "gcc-TEST",
        "X-Pull-Request": "https://forge.sourceware.org/gcc/gcc-TEST/pulls/47",
        "References": "\n <bmm.hhuo67grsc.gcc.gcc-TEST.fdumont.47.1.0@forge-stage.sourceware.org>",
        "In-Reply-To": "\n <bmm.hhuo67grsc.gcc.gcc-TEST.fdumont.47.1.0@forge-stage.sourceware.org>",
        "X-Patch-URL": "\n https://forge.sourceware.org/fdumont/gcc-TEST/commit/a0baa7a2e250ab9464566f27c5a3d6f2595bb166",
        "X-BeenThere": "gcc-patches@gcc.gnu.org",
        "X-Mailman-Version": "2.1.30",
        "Precedence": "list",
        "List-Id": "Gcc-patches mailing list <gcc-patches.gcc.gnu.org>",
        "List-Unsubscribe": "<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>",
        "List-Archive": "<https://gcc.gnu.org/pipermail/gcc-patches/>",
        "List-Post": "<mailto:gcc-patches@gcc.gnu.org>",
        "List-Help": "<mailto:gcc-patches-request@gcc.gnu.org?subject=help>",
        "List-Subscribe": "<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>",
        "Reply-To": "gcc-patches mailing list <gcc-patches@gcc.gnu.org>,\n fdumont@gcc.gnu.org",
        "Errors-To": "gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"
    },
    "content": "From: François Dumont <frs.dumont@gmail.com>\n\nIn revision a35dd276cbf6236e08bcf6e56e62c2be41cf6e3c the debug sequence\nhave been made mutable to allow attach iterators to const containers.\nThis change completes this fix by also declaring debug unordered container\nmembers mutable.\n\nAdditionally the debug iterator sequence is now a pointer-to-const and so\n_Safe_sequence_base _M_attach and all other methods are const qualified.\nNot-const methods exported are preserved for abi backward compatibility. The\nnew const methods are calling the latter thanks to a safe use of const_cast.\n\nlibstdc++-v3/ChangeLog:\n\n\tPR c++/116369\n\t* include/debug/safe_base.h\n\t(_Safe_iterator_base::_M_sequence): Declare as pointer-to-const.\n\t(_Safe_iterator_base::_M_attach, _M_attach_single): New, take pointer-to-const\n\t_Safe_sequence_base.\n\t(_Safe_sequence_base::_M_detach_all, _M_detach_singular, _M_revalidate_singular)\n\t(_M_swap, _M_get_mutex): New, const qualified.\n\t(_Safe_sequence_base::_M_attach, _M_attach_single, _M_detach, _M_detach_single):\n\tconst qualify.\n\t* include/debug/safe_container.h (_Safe_container<>::_M_cont): Add const qualifier.\n\t(_Safe_container<>::_M_swap_base): New.\n\t(_Safe_container(_Safe_container&&, const _Alloc&, std::false_type)):\n\tAdapt to use latter.\n\t(_Safe_container<>::operator=(_Safe_container&&)): Likewise.\n\t(_Safe_container<>::_M_swap): Likewise and take parameter as const reference.\n\t* include/debug/safe_unordered_base.h\n\t(_Safe_local_iterator_base::_M_safe_container): New.\n\t(_Safe_local_iterator_base::_Safe_local_iterator_base): Take\n\t_Safe_unordered_container_base as pointer-to-const.\n\t(_Safe_unordered_container_base::_M_attach, _M_attach_single): New, take\n\tcontainer as _Safe_unordered_container_base pointer-to-const.\n\t(_Safe_unordered_container_base::_M_local_iterators, _M_const_local_iterators):\n\tAdd mutable.\n\t(_Safe_unordered_container_base::_M_detach_all, _M_swap): New, const qualify.\n\t(_Safe_unordered_container_base::_M_attach_local, _M_attach_local_single)\n\t(_M_detach_local, _M_detach_local_single): Add const qualifier.\n\t* include/debug/safe_iterator.h (_Safe_iterator<>::_M_attach, _M_attach_single):\n\tTake _Safe_sequence_base as pointer-to-const.\n\t(_Safe_iterator<>::_M_get_sequence): Add const_cast and comment about it.\n\t* include/debug/safe_local_iterator.h (_Safe_local_iterator<>): Replace usages\n\tof _M_sequence member by _M_safe_container().\n\t(_Safe_local_iterator<>::_M_attach, _M_attach_single): Take\n\t_Safe_unordered_container_base as pointer-to-const.\n\t(_Safe_local_iterator<>::_M_get_sequence): Rename into...\n\t(_Safe_local_iterator<>::_M_get_ucontainer): ...this. Add necessary const_cast and\n\tcomment to explain it.\n\t(_Safe_local_iterator<>::_M_is_begin, _M_is_end): Adapt.\n\t* include/debug/safe_local_iterator.tcc: Adapt.\n\t* include/debug/safe_sequence.h\n\t(_Safe_sequence<>::_M_invalidate_if, _M_transfer_from_if): Add const qualifier.\n\t* include/debug/safe_sequence.tcc: Adapt.\n\t* include/debug/deque (std::__debug::deque::erase): Adapt to use new const\n\tqualified methods.\n\t* include/debug/formatter.h: Adapt.\n\t* include/debug/forward_list (_Safe_forward_list::_M_this): Add const\n\tqualification.\n\t(_Safe_forward_list::_M_swap_aux): Rename into...\n\t(_Safe_forward_list::_S_swap_aux): ...this and take sequence as const reference.\n\t(forward_list<>::resize): Adapt to use const methods.\n\t* include/debug/list (list<>::resize): Likewise.\n\t* src/c++11/debug.cc: Adapt to const qualification.\n\t* testsuite/util/testsuite_containers.h\n\t(forward_members_unordered::forward_members_unordered): Add check on local_iterator\n\tconversion to const_local_iterator.\n\t(forward_members::forward_members): Add check on iterator conversion to\n\tconst_iterator.\n\t* testsuite/23_containers/unordered_map/const_container.cc: New test case.\n\t* testsuite/23_containers/unordered_multimap/const_container.cc: New test case.\n\t* testsuite/23_containers/unordered_multiset/const_container.cc: New test case.\n\t* testsuite/23_containers/unordered_set/const_container.cc: New test case.\n\t* testsuite/23_containers/vector/debug/mutex_association.cc: Adapt.\n---\n libstdc++-v3/include/debug/deque              |   5 +-\n libstdc++-v3/include/debug/formatter.h        |  10 +-\n libstdc++-v3/include/debug/forward_list       |  71 ++++++------\n libstdc++-v3/include/debug/list               |  15 +--\n libstdc++-v3/include/debug/safe_base.h        |  83 ++++++++++----\n libstdc++-v3/include/debug/safe_container.h   |  25 +++--\n libstdc++-v3/include/debug/safe_iterator.h    |  14 ++-\n .../include/debug/safe_local_iterator.h       | 102 +++++++++---------\n .../include/debug/safe_local_iterator.tcc     |   4 +-\n libstdc++-v3/include/debug/safe_sequence.h    |   9 +-\n libstdc++-v3/include/debug/safe_sequence.tcc  |   6 +-\n .../include/debug/safe_unordered_base.h       |  85 ++++++++++++---\n .../include/debug/safe_unordered_container.h  |   4 +\n .../debug/safe_unordered_container.tcc        |   4 +-\n libstdc++-v3/src/c++11/debug.cc               |  64 +++++------\n .../unordered_map/const_container.cc          |  18 ++++\n .../unordered_multimap/const_container.cc     |  21 ++++\n .../unordered_multiset/const_container.cc     |  14 +++\n .../unordered_set/const_container.cc          |  13 +++\n .../vector/debug/mutex_association.cc         |   2 +-\n .../testsuite/util/testsuite_containers.h     |   6 ++\n 21 files changed, 386 insertions(+), 189 deletions(-)\n create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_map/const_container.cc\n create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_multimap/const_container.cc\n create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_multiset/const_container.cc\n create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_set/const_container.cc",
    "diff": "diff --git a/libstdc++-v3/include/debug/deque b/libstdc++-v3/include/debug/deque\nindex 59d60b2120db..ed69eb842e2b 100644\n--- a/libstdc++-v3/include/debug/deque\n+++ b/libstdc++-v3/include/debug/deque\n@@ -650,7 +650,8 @@ namespace __debug\n \telse if (__first.base() == _Base::begin()\n \t\t || __last.base() == _Base::end())\n \t  {\n-\t    this->_M_detach_singular();\n+\t    const deque* __this = this;\n+\t    __this->_M_detach_singular();\n \t    for (_Base_const_iterator __position = __first.base();\n \t\t __position != __last.base(); ++__position)\n \t      {\n@@ -663,7 +664,7 @@ namespace __debug\n \t      }\n \t    __catch(...)\n \t      {\n-\t\tthis->_M_revalidate_singular();\n+\t\t__this->_M_revalidate_singular();\n \t\t__throw_exception_again;\n \t      }\n \t  }\ndiff --git a/libstdc++-v3/include/debug/formatter.h b/libstdc++-v3/include/debug/formatter.h\nindex d80e8a78dcb4..8aa84adec778 100644\n--- a/libstdc++-v3/include/debug/formatter.h\n+++ b/libstdc++-v3/include/debug/formatter.h\n@@ -96,7 +96,7 @@ namespace __gnu_debug\n   template<typename _Iterator, typename _Sequence, typename _Category>\n     class _Safe_iterator;\n \n-  template<typename _Iterator, typename _Sequence>\n+  template<typename _Iterator, typename _UContainer>\n     class _Safe_local_iterator;\n \n   template<typename _Sequence>\n@@ -316,8 +316,8 @@ namespace __gnu_debug\n \t    }\n \t}\n \n-      template<typename _Iterator, typename _Sequence>\n-\t_Parameter(_Safe_local_iterator<_Iterator, _Sequence> const& __it,\n+      template<typename _Iterator, typename _UContainer>\n+\t_Parameter(_Safe_local_iterator<_Iterator, _UContainer> const& __it,\n \t\t   const char* __name, _Is_iterator)\n \t: _M_kind(__iterator),  _M_variant()\n \t{\n@@ -326,8 +326,8 @@ namespace __gnu_debug\n \t  _M_variant._M_iterator._M_type = _GLIBCXX_TYPEID(_Iterator);\n \t  _M_variant._M_iterator._M_constness =\n \t    __it._S_constant() ? __const_iterator : __mutable_iterator;\n-\t  _M_variant._M_iterator._M_sequence = __it._M_get_sequence();\n-\t  _M_variant._M_iterator._M_seq_type = _GLIBCXX_TYPEID(_Sequence);\n+\t  _M_variant._M_iterator._M_sequence = __it._M_get_ucontainer();\n+\t  _M_variant._M_iterator._M_seq_type = _GLIBCXX_TYPEID(_UContainer);\n \n \t  if (__it._M_singular())\n \t    {\ndiff --git a/libstdc++-v3/include/debug/forward_list b/libstdc++-v3/include/debug/forward_list\nindex 60a254297d54..4e1511da4e82 100644\n--- a/libstdc++-v3/include/debug/forward_list\n+++ b/libstdc++-v3/include/debug/forward_list\n@@ -58,44 +58,44 @@ namespace __gnu_debug\n     class _Safe_forward_list\n     : public _Safe_sequence<_SafeSequence>\n     {\n-      _SafeSequence&\n-      _M_this() noexcept\n-      { return *static_cast<_SafeSequence*>(this); }\n+      const _SafeSequence*\n+      _M_this() const noexcept\n+      { return static_cast<const _SafeSequence*>(this); }\n \n       static void\n-      _M_swap_aux(_Safe_sequence_base& __lhs,\n+      _S_swap_aux(const _Safe_forward_list& __lhs,\n \t\t  _Safe_iterator_base*& __lhs_iterators,\n-\t\t  _Safe_sequence_base& __rhs,\n+\t\t  const _Safe_forward_list& __rhs,\n \t\t  _Safe_iterator_base*& __rhs_iterators);\n \n-      void _M_swap_single(_Safe_sequence_base&) noexcept;\n+      void _M_swap_single(const _Safe_forward_list&) const noexcept;\n \n     protected:\n       void\n-      _M_invalidate_all()\n+      _M_invalidate_all() const\n       {\n-\tusing _Base_const_iterator = __decltype(_M_this()._M_base().cend());\n+\tusing _Base_const_iterator = __decltype(_M_this()->_M_base().cend());\n \tthis->_M_invalidate_if([this](_Base_const_iterator __it)\n \t{\n-\t  return __it != _M_this()._M_base().cbefore_begin()\n-\t    && __it != _M_this()._M_base().cend(); });\n+\t  return __it != _M_this()->_M_base().cbefore_begin()\n+\t    && __it != _M_this()->_M_base().cend(); });\n       }\n \n-      void _M_swap(_Safe_sequence_base&) noexcept;\n+      void\n+      _M_swap(const _Safe_forward_list&) const noexcept;\n     };\n \n    template<typename _SafeSequence>\n     void\n     _Safe_forward_list<_SafeSequence>::\n-    _M_swap_aux(_Safe_sequence_base& __lhs,\n+    _S_swap_aux(const _Safe_forward_list& __lhs,\n \t\t_Safe_iterator_base*& __lhs_iterators,\n-\t\t_Safe_sequence_base& __rhs,\n+\t\tconst _Safe_forward_list& __rhs,\n \t\t_Safe_iterator_base*& __rhs_iterators)\n     {\n       using const_iterator = typename _SafeSequence::const_iterator;\n       _Safe_iterator_base* __bbegin_its = 0;\n       _Safe_iterator_base* __last_bbegin = 0;\n-      _SafeSequence& __rseq = static_cast<_SafeSequence&>(__rhs);\n \n       for (_Safe_iterator_base* __iter = __lhs_iterators; __iter;)\n \t{\n@@ -104,7 +104,7 @@ namespace __gnu_debug\n \t  const_iterator* __victim =\n \t    static_cast<const_iterator*>(__victim_base);\n \t  __iter = __iter->_M_next;\n-\t  if (__victim->base() == __rseq._M_base().cbefore_begin())\n+\t  if (__victim->base() == __rhs._M_this()->_M_base().cbefore_begin())\n \t    {\n \t      __victim->_M_unlink();\n \t      if (__lhs_iterators == __victim_base)\n@@ -136,21 +136,21 @@ namespace __gnu_debug\n    template<typename _SafeSequence>\n     void\n     _Safe_forward_list<_SafeSequence>::\n-    _M_swap_single(_Safe_sequence_base& __other) noexcept\n+    _M_swap_single(const _Safe_forward_list& __other) const noexcept\n     {\n-      std::swap(_M_this()._M_iterators, __other._M_iterators);\n-      std::swap(_M_this()._M_const_iterators, __other._M_const_iterators);\n+      std::swap(_M_this()->_M_iterators, __other._M_iterators);\n+      std::swap(_M_this()->_M_const_iterators, __other._M_const_iterators);\n       // Useless, always 1 on forward_list\n-      //std::swap(_M_this()_M_version, __other._M_version);\n-      _Safe_iterator_base* __this_its = _M_this()._M_iterators;\n-      _M_swap_aux(__other, __other._M_iterators,\n-\t\t  _M_this(), _M_this()._M_iterators);\n-      _Safe_iterator_base* __this_const_its = _M_this()._M_const_iterators;\n-      _M_swap_aux(__other, __other._M_const_iterators,\n-\t\t  _M_this(), _M_this()._M_const_iterators);\n-      _M_swap_aux(_M_this(), __this_its,\n+      //std::swap(_M_this()->_M_version, __other._M_version);\n+      _Safe_iterator_base* __this_its = _M_this()->_M_iterators;\n+      _S_swap_aux(__other, __other._M_iterators,\n+\t\t  _M_this(), _M_this()->_M_iterators);\n+      _Safe_iterator_base* __this_const_its = _M_this()->_M_const_iterators;\n+      _S_swap_aux(__other, __other._M_const_iterators,\n+\t\t  _M_this(), _M_this()->_M_const_iterators);\n+      _S_swap_aux(_M_this(), __this_its,\n \t\t  __other, __other._M_iterators);\n-      _M_swap_aux(_M_this(), __this_const_its,\n+      _S_swap_aux(_M_this(), __this_const_its,\n \t\t  __other, __other._M_const_iterators);\n     }\n \n@@ -159,13 +159,12 @@ namespace __gnu_debug\n    template<typename _SafeSequence>\n     void\n     _Safe_forward_list<_SafeSequence>::\n-    _M_swap(_Safe_sequence_base& __other) noexcept\n+    _M_swap(const _Safe_forward_list& __other) const noexcept\n     {\n       // We need to lock both sequences to swap\n       using namespace __gnu_cxx;\n-      __mutex *__this_mutex = &_M_this()._M_get_mutex();\n-      __mutex *__other_mutex =\n-\t&static_cast<_SafeSequence&>(__other)._M_get_mutex();\n+      __mutex *__this_mutex = &_M_this()->_M_get_mutex();\n+      __mutex *__other_mutex = &__other._M_get_mutex();\n       if (__this_mutex == __other_mutex)\n \t{\n \t  __scoped_lock __lock(*__this_mutex);\n@@ -565,7 +564,8 @@ namespace __debug\n       void\n       resize(size_type __sz)\n       {\n-\tthis->_M_detach_singular();\n+\tconst forward_list* __this = this;\n+\t__this->_M_detach_singular();\n \n \t// if __sz < size(), invalidate all iterators in [begin+__sz, end()\n \t_Base_iterator __victim = _Base::begin();\n@@ -585,7 +585,7 @@ namespace __debug\n \t  }\n \t__catch(...)\n \t  {\n-\t    this->_M_revalidate_singular();\n+\t    __this->_M_revalidate_singular();\n \t    __throw_exception_again;\n \t  }\n       }\n@@ -593,7 +593,8 @@ namespace __debug\n       void\n       resize(size_type __sz, const value_type& __val)\n       {\n-\tthis->_M_detach_singular();\n+\tconst forward_list* __this = this;\n+\t__this->_M_detach_singular();\n \n \t// if __sz < size(), invalidate all iterators in [begin+__sz, end())\n \t_Base_iterator __victim = _Base::begin();\n@@ -613,7 +614,7 @@ namespace __debug\n \t  }\n \t__catch(...)\n \t  {\n-\t    this->_M_revalidate_singular();\n+\t    __this->_M_revalidate_singular();\n \t    __throw_exception_again;\n \t  }\n       }\ndiff --git a/libstdc++-v3/include/debug/list b/libstdc++-v3/include/debug/list\nindex a9d974c40a5d..c502c7cb6e23 100644\n--- a/libstdc++-v3/include/debug/list\n+++ b/libstdc++-v3/include/debug/list\n@@ -321,7 +321,8 @@ namespace __debug\n       void\n       resize(size_type __sz)\n       {\n-\tthis->_M_detach_singular();\n+\tconst list* __this = this;\n+\t__this->_M_detach_singular();\n \n \t// if __sz < size(), invalidate all iterators in [begin + __sz, end())\n \t_Base_iterator __victim = _Base::begin();\n@@ -338,7 +339,7 @@ namespace __debug\n \t  }\n \t__catch(...)\n \t  {\n-\t    this->_M_revalidate_singular();\n+\t    __this->_M_revalidate_singular();\n \t    __throw_exception_again;\n \t  }\n       }\n@@ -346,7 +347,8 @@ namespace __debug\n       void\n       resize(size_type __sz, const _Tp& __c)\n       {\n-\tthis->_M_detach_singular();\n+\tconst list* __this = this;\n+\t__this->_M_detach_singular();\n \n \t// if __sz < size(), invalidate all iterators in [begin + __sz, end())\n \t_Base_iterator __victim = _Base::begin();\n@@ -363,7 +365,7 @@ namespace __debug\n \t  }\n \t__catch(...)\n \t  {\n-\t    this->_M_revalidate_singular();\n+\t    __this->_M_revalidate_singular();\n \t    __throw_exception_again;\n \t  }\n       }\n@@ -371,7 +373,8 @@ namespace __debug\n       void\n       resize(size_type __sz, _Tp __c = _Tp())\n       {\n-\tthis->_M_detach_singular();\n+\tconst list* __this = this;\n+\t__this->_M_detach_singular();\n \n \t// if __sz < size(), invalidate all iterators in [begin + __sz, end())\n \t_Base_iterator __victim = _Base::begin();\n@@ -388,7 +391,7 @@ namespace __debug\n \t  }\n \t__catch(...)\n \t  {\n-\t    this->_M_revalidate_singular();\n+\t    __this->_M_revalidate_singular();\n \t    __throw_exception_again;\n \t  }\n       }\ndiff --git a/libstdc++-v3/include/debug/safe_base.h b/libstdc++-v3/include/debug/safe_base.h\nindex cf3f1708ad25..5719e40aedcc 100644\n--- a/libstdc++-v3/include/debug/safe_base.h\n+++ b/libstdc++-v3/include/debug/safe_base.h\n@@ -53,8 +53,10 @@ namespace __gnu_debug\n \n   public:\n     /** The sequence this iterator references; may be NULL to indicate\n-\ta singular iterator. */\n-    _Safe_sequence_base*\t_M_sequence;\n+     *  a singular iterator. Stored as pointer-to-const because sequence\n+     *  could be declared as const.\n+     */\n+    const _Safe_sequence_base*\t_M_sequence;\n \n     /** The version number of this iterator. The sentinel value 0 is\n      *  used to indicate an invalidated iterator (i.e., one that is\n@@ -92,7 +94,7 @@ namespace __gnu_debug\n     : _M_sequence(0), _M_version(0), _M_prior(0), _M_next(0)\n     {\n       if (!std::__is_constant_evaluated())\n-\tthis->_M_attach(const_cast<_Safe_sequence_base*>(__seq), __constant);\n+\tthis->_M_attach(__seq, __constant);\n     }\n \n     /** Initializes the iterator to reference the same sequence that\n@@ -115,7 +117,7 @@ namespace __gnu_debug\n \n     /** For use in _Safe_iterator. */\n     __gnu_cxx::__mutex&\n-    _M_get_mutex() throw ();\n+    _M_get_mutex() _GLIBCXX_USE_NOEXCEPT;\n \n     /** Attaches this iterator to the given sequence, detaching it\n      *\tfrom whatever sequence it was attached to originally. If the\n@@ -123,11 +125,14 @@ namespace __gnu_debug\n      *\tunattached.\n      */\n     void\n-    _M_attach(_Safe_sequence_base* __seq, bool __constant);\n+    _M_attach(const _Safe_sequence_base* __seq, bool __constant)\n+    { _M_attach(const_cast<_Safe_sequence_base*>(__seq), __constant); }\n \n     /** Likewise, but not thread-safe. */\n     void\n-    _M_attach_single(_Safe_sequence_base* __seq, bool __constant) throw ();\n+    _M_attach_single(const _Safe_sequence_base* __seq,\n+\t\t     bool __constant) _GLIBCXX_USE_NOEXCEPT\n+    { _M_attach_single(const_cast<_Safe_sequence_base*>(__seq), __constant); }\n \n     /** Detach the iterator for whatever sequence it is attached to,\n      *\tif any.\n@@ -135,10 +140,21 @@ namespace __gnu_debug\n     void\n     _M_detach();\n \n+  private:\n+    /***************************************************************/\n+    /** Not-const method preserved for abi backward compatibility. */\n+    void\n+    _M_attach(_Safe_sequence_base* __seq, bool __constant);\n+\n+    void\n+    _M_attach_single(_Safe_sequence_base* __seq,\n+\t\t     bool __constant) _GLIBCXX_USE_NOEXCEPT;\n+    /***************************************************************/\n+\n   public:\n     /** Likewise, but not thread-safe. */\n     void\n-    _M_detach_single() throw ();\n+    _M_detach_single() _GLIBCXX_USE_NOEXCEPT;\n \n     /** Determines if we are attached to the given sequence. */\n     bool\n@@ -147,13 +163,13 @@ namespace __gnu_debug\n \n     /** Is this iterator singular? */\n     _GLIBCXX_PURE bool\n-    _M_singular() const throw ();\n+    _M_singular() const _GLIBCXX_USE_NOEXCEPT;\n \n     /** Can we compare this iterator to the given iterator @p __x?\n \tReturns true if both iterators are nonsingular and reference\n \tthe same sequence. */\n     _GLIBCXX_PURE bool\n-    _M_can_compare(const _Safe_iterator_base& __x) const throw ();\n+    _M_can_compare(const _Safe_iterator_base& __x) const _GLIBCXX_USE_NOEXCEPT;\n \n     /** Invalidate the iterator, making it singular. */\n     void\n@@ -162,11 +178,11 @@ namespace __gnu_debug\n \n     /** Reset all member variables */\n     void\n-    _M_reset() throw ();\n+    _M_reset() _GLIBCXX_USE_NOEXCEPT;\n \n     /** Unlink itself */\n     void\n-    _M_unlink() throw ()\n+    _M_unlink() _GLIBCXX_USE_NOEXCEPT\n     {\n       if (_M_prior)\n \t_M_prior->_M_next = _M_next;\n@@ -246,14 +262,16 @@ namespace __gnu_debug\n \n     /** Detach all iterators, leaving them singular. */\n     void\n-    _M_detach_all();\n+    _M_detach_all() const\n+    { const_cast<_Safe_sequence_base*>(this)->_M_detach_all(); }\n \n     /** Detach all singular iterators.\n      *  @post for all iterators i attached to this sequence,\n      *   i->_M_version == _M_version.\n      */\n     void\n-    _M_detach_singular();\n+    _M_detach_singular() const\n+    { const_cast<_Safe_sequence_base*>(this)->_M_detach_singular(); }\n \n     /** Revalidates all attached singular iterators.  This method may\n      *  be used to validate iterators that were invalidated before\n@@ -261,7 +279,8 @@ namespace __gnu_debug\n      *  valid again).\n      */\n     void\n-    _M_revalidate_singular();\n+    _M_revalidate_singular() const\n+    { const_cast<_Safe_sequence_base*>(this)->_M_revalidate_singular(); }\n \n     /** Swap this sequence with the given sequence. This operation\n      *  also swaps ownership of the iterators, so that when the\n@@ -269,11 +288,16 @@ namespace __gnu_debug\n      *  one container now reference the other container.\n      */\n     void\n-    _M_swap(_Safe_sequence_base& __x) _GLIBCXX_USE_NOEXCEPT;\n+    _M_swap(const _Safe_sequence_base& __x) const _GLIBCXX_USE_NOEXCEPT\n+    {\n+      const_cast<_Safe_sequence_base*>(this)->_M_swap\n+\t(const_cast<_Safe_sequence_base&>(__x));\n+    }\n \n     /** For use in _Safe_sequence. */\n     __gnu_cxx::__mutex&\n-    _M_get_mutex() throw ();\n+    _M_get_mutex() const _GLIBCXX_USE_NOEXCEPT\n+    { return const_cast<_Safe_sequence_base*>(this)->_M_get_mutex(); }\n \n     /** Invalidates all iterators. */\n     void\n@@ -281,21 +305,40 @@ namespace __gnu_debug\n     { if (++_M_version == 0) _M_version = 1; }\n \n   private:\n+    /***************************************************************/\n+    /** Not-const method preserved for abi backward compatibility. */\n+    void\n+    _M_detach_all();\n+\n+    void\n+    _M_detach_singular();\n+\n+    void\n+    _M_revalidate_singular();\n+\n+    void\n+    _M_swap(_Safe_sequence_base& __x) _GLIBCXX_USE_NOEXCEPT;\n+\n+    __gnu_cxx::__mutex&\n+    _M_get_mutex() _GLIBCXX_USE_NOEXCEPT;\n+    /***************************************************************/\n+\n     /** Attach an iterator to this sequence. */\n     void\n-    _M_attach(_Safe_iterator_base* __it, bool __constant);\n+    _M_attach(_Safe_iterator_base* __it, bool __constant) const;\n \n     /** Likewise but not thread safe. */\n     void\n-    _M_attach_single(_Safe_iterator_base* __it, bool __constant) throw ();\n+    _M_attach_single(_Safe_iterator_base* __it,\n+\t\t     bool __constant) const _GLIBCXX_USE_NOEXCEPT;\n \n     /** Detach an iterator from this sequence */\n     void\n-    _M_detach(_Safe_iterator_base* __it);\n+    _M_detach(_Safe_iterator_base* __it) const;\n \n     /** Likewise but not thread safe. */\n     void\n-    _M_detach_single(_Safe_iterator_base* __it) throw ();\n+    _M_detach_single(_Safe_iterator_base* __it) const _GLIBCXX_USE_NOEXCEPT;\n   };\n } // namespace __gnu_debug\n \ndiff --git a/libstdc++-v3/include/debug/safe_container.h b/libstdc++-v3/include/debug/safe_container.h\nindex cb1e69a2d697..3341806fd596 100644\n--- a/libstdc++-v3/include/debug/safe_container.h\n+++ b/libstdc++-v3/include/debug/safe_container.h\n@@ -44,9 +44,9 @@ namespace __gnu_debug\n       typedef _SafeBase<_SafeContainer> _Base;\n \n       _GLIBCXX20_CONSTEXPR\n-      _SafeContainer&\n-      _M_cont() _GLIBCXX_NOEXCEPT\n-      { return *static_cast<_SafeContainer*>(this); }\n+      const _SafeContainer&\n+      _M_cont() const _GLIBCXX_NOEXCEPT\n+      { return *static_cast<const _SafeContainer*>(this); }\n \n     protected:\n #if __cplusplus >= 201103L\n@@ -55,6 +55,11 @@ namespace __gnu_debug\n       _Safe_container(_Safe_container&&) = default;\n \n     private:\n+      _GLIBCXX20_CONSTEXPR\n+      void\n+      _M_swap_base(const _Safe_container& __x) const noexcept\n+      { _Base::_M_swap(__x); }\n+\n       _GLIBCXX20_CONSTEXPR\n       _Safe_container(_Safe_container&& __x, const _Alloc&, std::true_type)\n       : _Safe_container(std::move(__x))\n@@ -67,7 +72,7 @@ namespace __gnu_debug\n \tif (!std::__is_constant_evaluated())\n \t  {\n \t    if (__x._M_cont().get_allocator() == __a)\n-\t      _Base::_M_swap(__x);\n+\t      _M_swap_base(__x);\n \t    else\n \t      __x._M_invalidate_all();\n \t  }\n@@ -115,12 +120,12 @@ namespace __gnu_debug\n \t    bool __xfer_memory = _Alloc_traits::_S_propagate_on_move_assign()\n \t      || _M_cont().get_allocator() == __x._M_cont().get_allocator();\n \t    if (__xfer_memory)\n-\t      _Base::_M_swap(__x);\n+\t      _M_swap_base(__x);\n \t    else\n \t      this->_M_invalidate_all();\n \t  }\n \telse\n-\t  _Base::_M_swap(__x);\n+\t  _M_swap_base(__x);\n \n \t__x._M_invalidate_all();\n \treturn *this;\n@@ -128,7 +133,7 @@ namespace __gnu_debug\n \n       _GLIBCXX20_CONSTEXPR\n       void\n-      _M_swap(_Safe_container& __x) noexcept\n+      _M_swap(const _Safe_container& __x) const noexcept\n       {\n \tif (_IsCxx11AllocatorAware)\n \t  {\n@@ -139,8 +144,12 @@ namespace __gnu_debug\n \t\t\t\t\t   __x._M_cont()._M_base());\n \t  }\n \n-\t_Base::_M_swap(__x);\n+\t_M_swap_base(__x);\n       }\n+#else\n+      void\n+      _M_swap(const _Safe_container& __x) const throw()\n+      { _Base::_M_swap(__x); }\n #endif\n     };\n \ndiff --git a/libstdc++-v3/include/debug/safe_iterator.h b/libstdc++-v3/include/debug/safe_iterator.h\nindex 7c563381d0bf..e0b1b46939c3 100644\n--- a/libstdc++-v3/include/debug/safe_iterator.h\n+++ b/libstdc++-v3/include/debug/safe_iterator.h\n@@ -224,7 +224,7 @@ namespace __gnu_debug\n \t\t\t      _M_message(__msg_init_copy_singular)\n \t\t\t      ._M_iterator(*this, \"this\")\n \t\t\t      ._M_iterator(__x, \"other\"));\n-\t_Safe_sequence_base* __seq = __x._M_sequence;\n+\tconst _Safe_sequence_base* __seq = __x._M_sequence;\n \t__x._M_detach();\n \tstd::swap(base(), __x.base());\n \t_M_attach(__seq);\n@@ -445,12 +445,12 @@ namespace __gnu_debug\n \n       /** Attach iterator to the given sequence. */\n       void\n-      _M_attach(_Safe_sequence_base* __seq)\n+      _M_attach(const _Safe_sequence_base* __seq)\n       { _Safe_base::_M_attach(__seq, _S_constant()); }\n \n       /** Likewise, but not thread-safe. */\n       void\n-      _M_attach_single(_Safe_sequence_base* __seq)\n+      _M_attach_single(const _Safe_sequence_base* __seq)\n       { _Safe_base::_M_attach_single(__seq, _S_constant()); }\n \n       /// Is the iterator dereferenceable?\n@@ -500,7 +500,13 @@ namespace __gnu_debug\n       typename __gnu_cxx::__conditional_type<\n \t_IsConstant::__value, const _Sequence*, _Sequence*>::__type\n       _M_get_sequence() const\n-      { return static_cast<_Sequence*>(_M_sequence); }\n+      {\n+\t// Looks like not const-correct, but if _IsConstant the constness\n+\t// is restored when returning the sequence pointer and if not\n+\t// _IsConstant we are allowed to remove constness.\n+\treturn static_cast<_Sequence*>\n+\t  (const_cast<_Safe_sequence_base*>(_M_sequence));\n+      }\n \n       // Get distance to __rhs.\n       typename _Distance_traits<_Iterator>::__type\ndiff --git a/libstdc++-v3/include/debug/safe_local_iterator.h b/libstdc++-v3/include/debug/safe_local_iterator.h\nindex c84f4f10093a..47b3a807a8bc 100644\n--- a/libstdc++-v3/include/debug/safe_local_iterator.h\n+++ b/libstdc++-v3/include/debug/safe_local_iterator.h\n@@ -52,15 +52,15 @@ namespace __gnu_debug\n   /** \\brief Safe iterator wrapper.\n    *\n    *  The class template %_Safe_local_iterator is a wrapper around an\n-   *  iterator that tracks the iterator's movement among sequences and\n-   *  checks that operations performed on the \"safe\" iterator are\n+   *  iterator that tracks the iterator's movement among unordered containers\n+   *  and checks that operations performed on the \"safe\" iterator are\n    *  legal. In additional to the basic iterator operations (which are\n    *  validated, and then passed to the underlying iterator),\n    *  %_Safe_local_iterator has member functions for iterator invalidation,\n-   *  attaching/detaching the iterator from sequences, and querying\n+   *  attaching/detaching the iterator from unordered containers, and querying\n    *  the iterator's state.\n    */\n-  template<typename _Iterator, typename _Sequence>\n+  template<typename _Iterator, typename _UContainer>\n     class _Safe_local_iterator\n     : private _Iterator\n     , public _Safe_local_iterator_base\n@@ -68,28 +68,27 @@ namespace __gnu_debug\n       typedef _Iterator _Iter_base;\n       typedef _Safe_local_iterator_base _Safe_base;\n \n-      typedef typename _Sequence::size_type size_type;\n+      typedef typename _UContainer::size_type size_type;\n \n       typedef std::iterator_traits<_Iterator> _Traits;\n \n-      typedef std::__are_same<\n-\ttypename _Sequence::_Base::const_local_iterator,\n-\t_Iterator> _IsConstant;\n+      using _IsConstant = std::__are_same<\n+\ttypename _UContainer::_Base::const_local_iterator, _Iterator>;\n \n-      typedef typename __gnu_cxx::__conditional_type<_IsConstant::__value,\n-\ttypename _Sequence::_Base::local_iterator,\n-\ttypename _Sequence::_Base::const_local_iterator>::__type\n-      _OtherIterator;\n+      using _OtherIterator = std::__conditional_t<\n+\t_IsConstant::__value,\n+\ttypename _UContainer::_Base::local_iterator,\n+\ttypename _UContainer::_Base::const_local_iterator>;\n \n       typedef _Safe_local_iterator _Self;\n-      typedef _Safe_local_iterator<_OtherIterator, _Sequence> _OtherSelf;\n+      typedef _Safe_local_iterator<_OtherIterator, _UContainer> _OtherSelf;\n \n       struct _Unchecked { };\n \n       _Safe_local_iterator(const _Safe_local_iterator& __x,\n \t\t\t   _Unchecked) noexcept\n       : _Iter_base(__x.base())\n-      { _M_attach(__x._M_sequence); }\n+      { _M_attach(__x._M_safe_container()); }\n \n     public:\n       typedef _Iterator\t\t\t\t\titerator_type;\n@@ -104,12 +103,13 @@ namespace __gnu_debug\n \n       /**\n        * @brief Safe iterator construction from an unsafe iterator and\n-       * its sequence.\n+       * its unordered container.\n        *\n-       * @pre @p seq is not NULL\n+       * @pre @p cont is not NULL\n        * @post this is not singular\n        */\n-      _Safe_local_iterator(_Iterator __i, const _Safe_sequence_base* __cont)\n+      _Safe_local_iterator(_Iterator __i,\n+\t\t\t   const _Safe_unordered_container_base* __cont)\n       : _Iter_base(__i), _Safe_base(__cont, _S_constant())\n       { }\n \n@@ -126,7 +126,7 @@ namespace __gnu_debug\n \t\t\t      _M_message(__msg_init_copy_singular)\n \t\t\t      ._M_iterator(*this, \"this\")\n \t\t\t      ._M_iterator(__x, \"other\"));\n-\t_M_attach(__x._M_sequence);\n+\t_M_attach(__x._M_safe_container());\n       }\n \n       /**\n@@ -141,7 +141,7 @@ namespace __gnu_debug\n \t\t\t      _M_message(__msg_init_copy_singular)\n \t\t\t      ._M_iterator(*this, \"this\")\n \t\t\t      ._M_iterator(__x, \"other\"));\n-\tauto __cont = __x._M_sequence;\n+\tauto __cont = __x._M_safe_container();\n \t__x._M_detach();\n \tstd::swap(base(), __x.base());\n \t_M_attach(__cont);\n@@ -156,7 +156,7 @@ namespace __gnu_debug\n \t  const _Safe_local_iterator<_MutableIterator,\n \t  typename __gnu_cxx::__enable_if<_IsConstant::__value &&\n \t    std::__are_same<_MutableIterator, _OtherIterator>::__value,\n-\t\t\t\t\t  _Sequence>::__type>& __x) noexcept\n+\t\t\t\t\t  _UContainer>::__type>& __x) noexcept\n \t: _Iter_base(__x.base())\n \t{\n \t  // _GLIBCXX_RESOLVE_LIB_DEFECTS\n@@ -166,7 +166,7 @@ namespace __gnu_debug\n \t\t\t\t_M_message(__msg_init_const_singular)\n \t\t\t\t._M_iterator(*this, \"this\")\n \t\t\t\t._M_iterator(__x, \"other\"));\n-\t  _M_attach(__x._M_sequence);\n+\t  _M_attach(__x._M_safe_container());\n \t}\n \n       /**\n@@ -193,7 +193,7 @@ namespace __gnu_debug\n \t  {\n \t    _M_detach();\n \t    base() = __x.base();\n-\t    _M_attach(__x._M_sequence);\n+\t    _M_attach(__x._M_safe_container());\n \t  }\n \n \treturn *this;\n@@ -225,7 +225,7 @@ namespace __gnu_debug\n \t  {\n \t    _M_detach();\n \t    base() = __x.base();\n-\t    _M_attach(__x._M_sequence);\n+\t    _M_attach(__x._M_safe_container());\n \t  }\n \n \t__x._M_detach();\n@@ -318,15 +318,15 @@ namespace __gnu_debug\n        */\n       operator _Iterator() const { return *this; }\n \n-      /** Attach iterator to the given sequence. */\n+      /** Attach iterator to the given unordered container. */\n       void\n-      _M_attach(_Safe_sequence_base* __seq)\n-      { _Safe_base::_M_attach(__seq, _S_constant()); }\n+      _M_attach(const _Safe_unordered_container_base* __cont)\n+      { _Safe_base::_M_attach(__cont, _S_constant()); }\n \n       /** Likewise, but not thread-safe. */\n       void\n-      _M_attach_single(_Safe_sequence_base* __seq)\n-      { _Safe_base::_M_attach_single(__seq, _S_constant()); }\n+      _M_attach_single(const _Safe_unordered_container_base* __cont)\n+      { _Safe_base::_M_attach_single(__cont, _S_constant()); }\n \n       /// Is the iterator dereferenceable?\n       bool\n@@ -353,25 +353,31 @@ namespace __gnu_debug\n       typename _Distance_traits<_Iterator>::__type\n       _M_get_distance_to(const _Safe_local_iterator& __rhs) const;\n \n-      // The sequence this iterator references.\n-      typename __gnu_cxx::__conditional_type<\n-\t_IsConstant::__value, const _Sequence*, _Sequence*>::__type\n-      _M_get_sequence() const\n-      { return static_cast<_Sequence*>(_M_sequence); }\n+      // The unordered container this iterator references.\n+      std::__conditional_t<\n+\t_IsConstant::__value, const _UContainer*, _UContainer*>\n+      _M_get_ucontainer() const\n+      {\n+\t// Looks like not const-correct, but if _IsConstant the constness\n+\t// is restored when returning the container pointer and if not\n+\t// _IsConstant we are allowed to remove constness.\n+\treturn static_cast<_UContainer*>\n+\t  (const_cast<_Safe_unordered_container_base*>(_M_safe_container()));\n+      }\n \n-      /// Is this iterator equal to the sequence's begin(bucket) iterator?\n+      /// Is this iterator equal to the container's begin(bucket) iterator?\n       bool _M_is_begin() const\n-      { return base() == _M_get_sequence()->_M_base().begin(bucket()); }\n+      { return base() == _M_get_ucontainer()->_M_base().begin(bucket()); }\n \n-      /// Is this iterator equal to the sequence's end(bucket) iterator?\n+      /// Is this iterator equal to the container's end(bucket) iterator?\n       bool _M_is_end() const\n-      { return base() == _M_get_sequence()->_M_base().end(bucket()); }\n+      { return base() == _M_get_ucontainer()->_M_base().end(bucket()); }\n \n       /// Is this iterator part of the same bucket as the other one?\n       template<typename _Other>\n \tbool\n \t_M_in_same_bucket(const _Safe_local_iterator<_Other,\n-\t\t\t\t\t\t     _Sequence>& __other) const\n+\t\t\t\t\t\t     _UContainer>& __other) const\n \t{ return bucket() == __other.bucket(); }\n \n       friend inline bool\n@@ -404,31 +410,31 @@ namespace __gnu_debug\n     };\n \n   /** Safe local iterators know how to check if they form a valid range. */\n-  template<typename _Iterator, typename _Sequence>\n+  template<typename _Iterator, typename _UContainer>\n     inline bool\n-    __valid_range(const _Safe_local_iterator<_Iterator, _Sequence>& __first,\n-\t\t  const _Safe_local_iterator<_Iterator, _Sequence>& __last,\n+    __valid_range(const _Safe_local_iterator<_Iterator, _UContainer>& __first,\n+\t\t  const _Safe_local_iterator<_Iterator, _UContainer>& __last,\n \t\t  typename _Distance_traits<_Iterator>::__type& __dist_info)\n     { return __first._M_valid_range(__last, __dist_info); }\n \n-  template<typename _Iterator, typename _Sequence>\n+  template<typename _Iterator, typename _UContainer>\n     inline bool\n-    __valid_range(const _Safe_local_iterator<_Iterator, _Sequence>& __first,\n-\t\t  const _Safe_local_iterator<_Iterator, _Sequence>& __last)\n+    __valid_range(const _Safe_local_iterator<_Iterator, _UContainer>& __first,\n+\t\t  const _Safe_local_iterator<_Iterator, _UContainer>& __last)\n     {\n       typename _Distance_traits<_Iterator>::__type __dist_info;\n       return __first._M_valid_range(__last, __dist_info);\n     }\n \n #if __cplusplus < 201103L\n-  template<typename _Iterator, typename _Sequence>\n-    struct _Unsafe_type<_Safe_local_iterator<_Iterator, _Sequence> >\n+  template<typename _Iterator, typename _UContainer>\n+    struct _Unsafe_type<_Safe_local_iterator<_Iterator, _UContainer> >\n     { typedef _Iterator _Type; };\n #endif\n \n-  template<typename _Iterator, typename _Sequence>\n+  template<typename _Iterator, typename _UContainer>\n     inline _Iterator\n-    __unsafe(const _Safe_local_iterator<_Iterator, _Sequence>& __it)\n+    __unsafe(const _Safe_local_iterator<_Iterator, _UContainer>& __it)\n     { return __it.base(); }\n \n } // namespace __gnu_debug\ndiff --git a/libstdc++-v3/include/debug/safe_local_iterator.tcc b/libstdc++-v3/include/debug/safe_local_iterator.tcc\nindex 71e532065e4f..10fec3fad4a7 100644\n--- a/libstdc++-v3/include/debug/safe_local_iterator.tcc\n+++ b/libstdc++-v3/include/debug/safe_local_iterator.tcc\n@@ -44,7 +44,7 @@ namespace __gnu_debug\n \t  if (__rhs._M_is_end())\n \t    return\n \t      {\n-\t\t_M_get_sequence()->bucket_size(bucket()),\n+\t\t_M_get_ucontainer()->bucket_size(bucket()),\n \t\t__dp_exact\n \t      };\n \n@@ -56,7 +56,7 @@ namespace __gnu_debug\n \t  if (__rhs._M_is_begin())\n \t    return\n \t      {\n-\t\t-_M_get_sequence()->bucket_size(bucket()),\n+\t\t-_M_get_ucontainer()->bucket_size(bucket()),\n \t\t__dp_exact\n \t      };\n \ndiff --git a/libstdc++-v3/include/debug/safe_sequence.h b/libstdc++-v3/include/debug/safe_sequence.h\nindex 6b35afa66c63..e10474aae79c 100644\n--- a/libstdc++-v3/include/debug/safe_sequence.h\n+++ b/libstdc++-v3/include/debug/safe_sequence.h\n@@ -114,7 +114,7 @@ namespace __gnu_debug\n \t  in the safe ones. */\n       template<typename _Predicate>\n \tvoid\n-\t_M_invalidate_if(_Predicate __pred);\n+\t_M_invalidate_if(_Predicate __pred) const;\n \n       /** Transfers all iterators @c x that reference @c from sequence,\n \t  are not singular, and for which @c __pred(x) returns @c\n@@ -122,7 +122,8 @@ namespace __gnu_debug\n \t  in the safe ones. */\n       template<typename _Predicate>\n \tvoid\n-\t_M_transfer_from_if(_Safe_sequence& __from, _Predicate __pred);\n+\t_M_transfer_from_if(const _Safe_sequence& __from,\n+\t\t\t    _Predicate __pred) const;\n     };\n \n   /// Like _Safe_sequence but with a special _M_invalidate_all implementation\n@@ -133,12 +134,12 @@ namespace __gnu_debug\n     {\n     protected:\n       void\n-      _M_invalidate_all()\n+      _M_invalidate_all() const\n       {\n \ttypedef typename _Sequence::const_iterator _Const_iterator;\n \ttypedef typename _Const_iterator::iterator_type _Base_const_iterator;\n \ttypedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;\n-\tconst _Sequence& __seq = *static_cast<_Sequence*>(this);\n+\tconst _Sequence& __seq = *static_cast<const _Sequence*>(this);\n \tthis->_M_invalidate_if(_Not_equal(__seq._M_base().end()));\n       }\n     };\ndiff --git a/libstdc++-v3/include/debug/safe_sequence.tcc b/libstdc++-v3/include/debug/safe_sequence.tcc\nindex 336bf2a0b2b6..053361dff3c0 100644\n--- a/libstdc++-v3/include/debug/safe_sequence.tcc\n+++ b/libstdc++-v3/include/debug/safe_sequence.tcc\n@@ -35,7 +35,7 @@ namespace __gnu_debug\n     template<typename _Predicate>\n       void\n       _Safe_sequence<_Sequence>::\n-      _M_invalidate_if(_Predicate __pred)\n+      _M_invalidate_if(_Predicate __pred) const\n       {\n \ttypedef typename _Sequence::iterator iterator;\n \ttypedef typename _Sequence::const_iterator const_iterator;\n@@ -66,7 +66,7 @@ namespace __gnu_debug\n     template<typename _Predicate>\n       void\n       _Safe_sequence<_Sequence>::\n-      _M_transfer_from_if(_Safe_sequence& __from, _Predicate __pred)\n+      _M_transfer_from_if(const _Safe_sequence& __from, _Predicate __pred) const\n       {\n \tif (this == std::__addressof(__from))\n \t  return;\n@@ -104,7 +104,7 @@ namespace __gnu_debug\n \t    }\n \n \t  for (_Safe_iterator_base* __iter2 = __from._M_const_iterators;\n-\t\t __iter2;)\n+\t       __iter2;)\n \t    {\n \t      _Safe_iterator_base* __victim_base = __iter2;\n \t      const_iterator* __victim =\ndiff --git a/libstdc++-v3/include/debug/safe_unordered_base.h b/libstdc++-v3/include/debug/safe_unordered_base.h\nindex 1547f5b7b9d5..169cd6961764 100644\n--- a/libstdc++-v3/include/debug/safe_unordered_base.h\n+++ b/libstdc++-v3/include/debug/safe_unordered_base.h\n@@ -49,6 +49,10 @@ namespace __gnu_debug\n    */\n   class _Safe_local_iterator_base : public _Safe_iterator_base\n   {\n+  public:\n+    const _Safe_unordered_container_base*\n+    _M_safe_container() const noexcept;\n+\n   protected:\n     /** Initializes the iterator and makes it singular. */\n     _Safe_local_iterator_base()\n@@ -61,32 +65,32 @@ namespace __gnu_debug\n      *  singular. Otherwise, the iterator will reference @p __seq and\n      *  be nonsingular.\n      */\n-    _Safe_local_iterator_base(const _Safe_sequence_base* __seq, bool __constant)\n-    { this->_M_attach(const_cast<_Safe_sequence_base*>(__seq), __constant); }\n+    _Safe_local_iterator_base(const _Safe_unordered_container_base* __seq,\n+\t\t\t      bool __constant)\n+    { _M_attach(__seq, __constant); }\n \n     /** Initializes the iterator to reference the same container that\n \t@p __x does. @p __constant is true if this is a constant\n \titerator, and false if it is mutable. */\n     _Safe_local_iterator_base(const _Safe_local_iterator_base& __x,\n \t\t\t      bool __constant)\n-    { this->_M_attach(__x._M_sequence, __constant); }\n+    { this->_M_attach(__x._M_safe_container(), __constant); }\n \n     ~_Safe_local_iterator_base() { this->_M_detach(); }\n \n-    _Safe_unordered_container_base*\n-    _M_get_container() const noexcept;\n-\n     /** Attaches this iterator to the given container, detaching it\n      *\tfrom whatever container it was attached to originally. If the\n      *\tnew container is the NULL pointer, the iterator is left\n      *\tunattached.\n      */\n     void\n-    _M_attach(_Safe_sequence_base* __seq, bool __constant);\n+    _M_attach(const _Safe_unordered_container_base* __cont,\n+\t      bool __constant);\n \n     /** Likewise, but not thread-safe. */\n     void\n-    _M_attach_single(_Safe_sequence_base* __seq, bool __constant) throw ();\n+    _M_attach_single(const _Safe_unordered_container_base* __cont,\n+\t\t     bool __constant) noexcept;\n \n     /** Detach the iterator for whatever container it is attached to,\n      *\tif any.\n@@ -96,7 +100,17 @@ namespace __gnu_debug\n \n     /** Likewise, but not thread-safe. */\n     void\n-    _M_detach_single() throw ();\n+    _M_detach_single() noexcept;\n+\n+  private:\n+    /***************************************************************/\n+    /** Not-const method preserved for abi backward compatibility. */\n+    void\n+    _M_attach(_Safe_sequence_base* __seq, bool __constant);\n+\n+    void\n+    _M_attach_single(_Safe_sequence_base* __seq, bool __constant) noexcept;\n+    /***************************************************************/\n   };\n \n   /**\n@@ -124,10 +138,10 @@ namespace __gnu_debug\n \n   public:\n     /// The list of mutable local iterators that reference this container\n-    _Safe_iterator_base* _M_local_iterators;\n+    mutable _Safe_iterator_base* _M_local_iterators;\n \n     /// The list of constant local iterators that reference this container\n-    _Safe_iterator_base* _M_const_local_iterators;\n+    mutable _Safe_iterator_base* _M_const_local_iterators;\n \n   protected:\n     // Initialize with a version number of 1 and no iterators\n@@ -153,7 +167,8 @@ namespace __gnu_debug\n \n     /** Detach all iterators, leaving them singular. */\n     void\n-    _M_detach_all();\n+    _M_detach_all() const\n+    { const_cast<_Safe_unordered_container_base*>(this)->_M_detach_all(); }\n \n     /** Swap this container with the given container. This operation\n      *  also swaps ownership of the iterators, so that when the\n@@ -161,25 +176,61 @@ namespace __gnu_debug\n      *  one container now reference the other container.\n      */\n     void\n-    _M_swap(_Safe_unordered_container_base& __x) noexcept;\n+    _M_swap(const _Safe_unordered_container_base& __x) const noexcept\n+    {\n+      const_cast<_Safe_unordered_container_base*>(this)->_M_swap\n+\t(const_cast<_Safe_unordered_container_base&>(__x));\n+    }\n \n   private:\n+    /***************************************************************/\n+    /** Not-const method preserved for abi backward compatibility. */\n+    void\n+    _M_detach_all();\n+\n+    void\n+    _M_swap(_Safe_unordered_container_base& __x) noexcept;\n+    /***************************************************************/\n+\n     /** Attach an iterator to this container. */\n     void\n-    _M_attach_local(_Safe_iterator_base* __it, bool __constant);\n+    _M_attach_local(_Safe_iterator_base* __it, bool __constant) const;\n \n     /** Likewise but not thread safe. */\n     void\n-    _M_attach_local_single(_Safe_iterator_base* __it, bool __constant) throw ();\n+    _M_attach_local_single(_Safe_iterator_base* __it,\n+\t\t\t   bool __constant) const noexcept;\n \n     /** Detach an iterator from this container */\n     void\n-    _M_detach_local(_Safe_iterator_base* __it);\n+    _M_detach_local(_Safe_iterator_base* __it) const;\n \n     /** Likewise but not thread safe. */\n     void\n-    _M_detach_local_single(_Safe_iterator_base* __it) throw ();\n+    _M_detach_local_single(_Safe_iterator_base* __it) const noexcept;\n   };\n+\n+  inline const _Safe_unordered_container_base*\n+  _Safe_local_iterator_base::\n+  _M_safe_container() const noexcept\n+  { return static_cast<const _Safe_unordered_container_base*>(_M_sequence); }\n+\n+  inline void\n+  _Safe_local_iterator_base::\n+  _M_attach(const _Safe_unordered_container_base* __cont, bool __constant)\n+  {\n+    const _Safe_sequence_base* __seq = __cont;\n+    _M_attach(const_cast<_Safe_sequence_base*>(__seq), __constant);\n+  }\n+\n+  inline void\n+  _Safe_local_iterator_base::\n+  _M_attach_single(const _Safe_unordered_container_base* __cont,\n+\t\t   bool __constant) noexcept\n+  {\n+    const _Safe_sequence_base* __seq = __cont;\n+    _M_attach_single(const_cast<_Safe_sequence_base*>(__seq), __constant);\n+  }\n } // namespace __gnu_debug\n \n #endif\ndiff --git a/libstdc++-v3/include/debug/safe_unordered_container.h b/libstdc++-v3/include/debug/safe_unordered_container.h\nindex 2ba27dbbecbb..b67b7e06b2fc 100644\n--- a/libstdc++-v3/include/debug/safe_unordered_container.h\n+++ b/libstdc++-v3/include/debug/safe_unordered_container.h\n@@ -62,6 +62,10 @@ namespace __gnu_debug\n       _M_cont() noexcept\n       { return *static_cast<_Container*>(this); }\n \n+      const _Safe_unordered_container*\n+      _M_self() const\n+      { return this; }\n+\n     protected:\n       void\n       _M_invalidate_locals()\ndiff --git a/libstdc++-v3/include/debug/safe_unordered_container.tcc b/libstdc++-v3/include/debug/safe_unordered_container.tcc\nindex 68193891b01d..0732e6374bfc 100644\n--- a/libstdc++-v3/include/debug/safe_unordered_container.tcc\n+++ b/libstdc++-v3/include/debug/safe_unordered_container.tcc\n@@ -40,7 +40,7 @@ namespace __gnu_debug\n \ttypedef typename _Container::iterator iterator;\n \ttypedef typename _Container::const_iterator const_iterator;\n \n-\t__gnu_cxx::__scoped_lock sentry(this->_M_get_mutex());\n+\t__gnu_cxx::__scoped_lock sentry(_M_self()->_M_get_mutex());\n \tfor (_Safe_iterator_base* __iter = _M_iterators; __iter;)\n \t  {\n \t    iterator* __victim = static_cast<iterator*>(__iter);\n@@ -72,7 +72,7 @@ namespace __gnu_debug\n \ttypedef typename _Container::local_iterator local_iterator;\n \ttypedef typename _Container::const_local_iterator const_local_iterator;\n \n-\t__gnu_cxx::__scoped_lock sentry(this->_M_get_mutex());\n+\t__gnu_cxx::__scoped_lock sentry(_M_self()->_M_get_mutex());\n \tfor (_Safe_iterator_base* __iter = _M_local_iterators; __iter;)\n \t  {\n \t    local_iterator* __victim = static_cast<local_iterator*>(__iter);\ndiff --git a/libstdc++-v3/src/c++11/debug.cc b/libstdc++-v3/src/c++11/debug.cc\nindex 3533b5e1df12..92c76ac6eb94 100644\n--- a/libstdc++-v3/src/c++11/debug.cc\n+++ b/libstdc++-v3/src/c++11/debug.cc\n@@ -54,7 +54,7 @@ namespace\n    *  in order to limit contention without breaking current library binary\n    *  compatibility. */\n   __gnu_cxx::__mutex&\n-  get_safe_base_mutex(void* address)\n+  get_safe_base_mutex(const void* address)\n   {\n     // Use arbitrarily __gnu_debug::vector<int> as the container giving\n     // alignment of debug containers.\n@@ -70,9 +70,9 @@ namespace\n #pragma GCC diagnostic warning \"-Wabi=6\"\n \n   void\n-  swap_its(__gnu_debug::_Safe_sequence_base& __lhs,\n+  swap_its(const __gnu_debug::_Safe_sequence_base& __lhs,\n \t   __gnu_debug::_Safe_iterator_base*& __lhs_its,\n-\t   __gnu_debug::_Safe_sequence_base& __rhs,\n+\t   const __gnu_debug::_Safe_sequence_base& __rhs,\n \t   __gnu_debug::_Safe_iterator_base*& __rhs_its)\n   {\n     swap(__lhs_its, __rhs_its);\n@@ -84,8 +84,8 @@ namespace\n   }\n \n   void\n-  swap_seq_single(__gnu_debug::_Safe_sequence_base& __lhs,\n-\t\t  __gnu_debug::_Safe_sequence_base& __rhs)\n+  swap_seq_single(const __gnu_debug::_Safe_sequence_base& __lhs,\n+\t\t  const __gnu_debug::_Safe_sequence_base& __rhs)\n   {\n     swap(__lhs._M_version, __rhs._M_version);\n     swap_its(__lhs, __lhs._M_iterators,\n@@ -118,17 +118,17 @@ namespace\n \n   void\n   swap_seq(__gnu_cxx::__mutex& lhs_mutex,\n-\t   __gnu_debug::_Safe_sequence_base& lhs,\n+\t   const __gnu_debug::_Safe_sequence_base& lhs,\n \t   __gnu_cxx::__mutex& rhs_mutex,\n-\t   __gnu_debug::_Safe_sequence_base& rhs)\n+\t   const __gnu_debug::_Safe_sequence_base& rhs)\n   {\n     lock_and_run(lhs_mutex, rhs_mutex,\n \t\t [&lhs, &rhs]() { swap_seq_single(lhs, rhs); });\n   }\n \n   void\n-  swap_ucont_single(__gnu_debug::_Safe_unordered_container_base& __lhs,\n-\t\t    __gnu_debug::_Safe_unordered_container_base& __rhs)\n+  swap_ucont_single(const __gnu_debug::_Safe_unordered_container_base& __lhs,\n+\t\t    const __gnu_debug::_Safe_unordered_container_base& __rhs)\n   {\n     swap_seq_single(__lhs, __rhs);\n     swap_its(__lhs, __lhs._M_local_iterators,\n@@ -139,9 +139,9 @@ namespace\n \n   void\n   swap_ucont(__gnu_cxx::__mutex& lhs_mutex,\n-\t     __gnu_debug::_Safe_unordered_container_base& lhs,\n+\t     const __gnu_debug::_Safe_unordered_container_base& lhs,\n \t     __gnu_cxx::__mutex& rhs_mutex,\n-\t     __gnu_debug::_Safe_unordered_container_base& rhs)\n+\t     const __gnu_debug::_Safe_unordered_container_base& rhs)\n   {\n     lock_and_run(lhs_mutex, rhs_mutex,\n \t\t [&lhs, &rhs]() { swap_ucont_single(lhs, rhs); });\n@@ -158,8 +158,8 @@ namespace\n       }\n   }\n \n-  void*\n-  acquire_sequence_ptr_for_lock(__gnu_debug::_Safe_sequence_base*& seq)\n+  const void*\n+  acquire_sequence_ptr_for_lock(__gnu_debug::_Safe_sequence_base const*& seq)\n   {\n #ifdef __GTHREADS\n     if (!__gnu_cxx::__is_single_threaded())\n@@ -169,7 +169,7 @@ namespace\n   }\n \n   void\n-  reset_sequence_ptr(__gnu_debug::_Safe_sequence_base*& seq)\n+  reset_sequence_ptr(__gnu_debug::_Safe_sequence_base const*& seq)\n   {\n #ifdef __GTHREADS\n     if (!__gnu_cxx::__is_single_threaded())\n@@ -385,7 +385,7 @@ namespace __gnu_debug\n \n   void\n   _Safe_sequence_base::\n-  _M_attach(_Safe_iterator_base* __it, bool __constant)\n+  _M_attach(_Safe_iterator_base* __it, bool __constant) const\n   {\n     __gnu_cxx::__scoped_lock sentry(_M_get_mutex());\n     _M_attach_single(__it, __constant);\n@@ -393,7 +393,7 @@ namespace __gnu_debug\n \n   void\n   _Safe_sequence_base::\n-  _M_attach_single(_Safe_iterator_base* __it, bool __constant) noexcept\n+  _M_attach_single(_Safe_iterator_base* __it, bool __constant) const noexcept\n   {\n     _Safe_iterator_base*& __its =\n       __constant ? _M_const_iterators : _M_iterators;\n@@ -405,7 +405,7 @@ namespace __gnu_debug\n \n   void\n   _Safe_sequence_base::\n-  _M_detach(_Safe_iterator_base* __it)\n+  _M_detach(_Safe_iterator_base* __it) const\n   {\n     // Remove __it from this sequence's list\n     __gnu_cxx::__scoped_lock sentry(_M_get_mutex());\n@@ -414,7 +414,7 @@ namespace __gnu_debug\n \n   void\n   _Safe_sequence_base::\n-  _M_detach_single(_Safe_iterator_base* __it) noexcept\n+  _M_detach_single(_Safe_iterator_base* __it) const noexcept\n   {\n     // Remove __it from this sequence's list\n     __it->_M_unlink();\n@@ -514,11 +514,6 @@ namespace __gnu_debug\n   _M_get_mutex() noexcept\n   { return _M_sequence->_M_get_mutex(); }\n \n-  _Safe_unordered_container_base*\n-  _Safe_local_iterator_base::\n-  _M_get_container() const noexcept\n-  { return static_cast<_Safe_unordered_container_base*>(_M_sequence); }\n-\n   void\n   _Safe_local_iterator_base::\n   _M_attach(_Safe_sequence_base* __cont, bool __constant)\n@@ -530,7 +525,7 @@ namespace __gnu_debug\n       {\n \t_M_sequence = __cont;\n \t_M_version = _M_sequence->_M_version;\n-\t_M_get_container()->_M_attach_local(this, __constant);\n+\t_M_safe_container()->_M_attach_local(this, __constant);\n       }\n     else\n       _M_version = 0;\n@@ -547,7 +542,7 @@ namespace __gnu_debug\n       {\n \t_M_sequence = __cont;\n \t_M_version = _M_sequence->_M_version;\n-\t_M_get_container()->_M_attach_local_single(this, __constant);\n+\t_M_safe_container()->_M_attach_local_single(this, __constant);\n       }\n     else\n       _M_version = 0;\n@@ -570,7 +565,7 @@ namespace __gnu_debug\n   {\n     if (_M_sequence)\n       {\n-\t_M_get_container()->_M_detach_local_single(this);\n+\t_M_safe_container()->_M_detach_local_single(this);\n \t_M_reset();\n       }\n   }\n@@ -579,7 +574,8 @@ namespace __gnu_debug\n   _Safe_unordered_container_base::\n   _M_detach_all()\n   {\n-    __gnu_cxx::__scoped_lock sentry(_M_get_mutex());\n+    const _Safe_unordered_container_base& __cont = *this;\n+    __gnu_cxx::__scoped_lock sentry(__cont._M_get_mutex());\n     detach_all(_M_iterators);\n     _M_iterators = 0;\n \n@@ -596,11 +592,15 @@ namespace __gnu_debug\n   void\n   _Safe_unordered_container_base::\n   _M_swap(_Safe_unordered_container_base& __x) noexcept\n-  { swap_ucont(_M_get_mutex(), *this, __x._M_get_mutex(), __x); }\n+  {\n+    const _Safe_unordered_container_base& __cont = *this;\n+    const _Safe_unordered_container_base& __x_cont = __x;\n+    swap_ucont(__cont._M_get_mutex(), *this, __x_cont._M_get_mutex(), __x);\n+  }\n \n   void\n   _Safe_unordered_container_base::\n-  _M_attach_local(_Safe_iterator_base* __it, bool __constant)\n+  _M_attach_local(_Safe_iterator_base* __it, bool __constant) const\n   {\n     __gnu_cxx::__scoped_lock sentry(_M_get_mutex());\n     _M_attach_local_single(__it, __constant);\n@@ -608,7 +608,7 @@ namespace __gnu_debug\n \n   void\n   _Safe_unordered_container_base::\n-  _M_attach_local_single(_Safe_iterator_base* __it, bool __constant) noexcept\n+  _M_attach_local_single(_Safe_iterator_base* __it, bool __constant) const noexcept\n   {\n     _Safe_iterator_base*& __its =\n       __constant ? _M_const_local_iterators : _M_local_iterators;\n@@ -620,7 +620,7 @@ namespace __gnu_debug\n \n   void\n   _Safe_unordered_container_base::\n-  _M_detach_local(_Safe_iterator_base* __it)\n+  _M_detach_local(_Safe_iterator_base* __it) const\n   {\n     // Remove __it from this container's list\n     __gnu_cxx::__scoped_lock sentry(_M_get_mutex());\n@@ -629,7 +629,7 @@ namespace __gnu_debug\n \n   void\n   _Safe_unordered_container_base::\n-  _M_detach_local_single(_Safe_iterator_base* __it) noexcept\n+  _M_detach_local_single(_Safe_iterator_base* __it) const noexcept\n   {\n     // Remove __it from this container's list\n     __it->_M_unlink();\ndiff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/const_container.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/const_container.cc\nnew file mode 100644\nindex 000000000000..71b8bfec85ad\n--- /dev/null\n+++ b/libstdc++-v3/testsuite/23_containers/unordered_map/const_container.cc\n@@ -0,0 +1,18 @@\n+// { dg-do compile { target c++11 } }\n+\n+#include <unordered_map>\n+\n+#include <testsuite_hooks.h>\n+\n+int main()\n+{\n+  const std::unordered_map<int, int> um\n+    {\n+      { 0, 1 },\n+      { 2, 3 },\n+      { 4, 5 }\n+    };\n+\n+  VERIFY( um.size() == 3 );\n+  VERIFY( um.find(0) != um.end() );\n+}\ndiff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/const_container.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/const_container.cc\nnew file mode 100644\nindex 000000000000..376e922a671e\n--- /dev/null\n+++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/const_container.cc\n@@ -0,0 +1,21 @@\n+// { dg-do compile { target c++11 } }\n+\n+#include <unordered_map>\n+\n+#include <testsuite_hooks.h>\n+\n+int main()\n+{\n+  const std::unordered_multimap<int, int> umm\n+    {\n+      { 0, 1 },\n+      { 0, 1 },\n+      { 2, 3 },\n+      { 2, 3 },\n+      { 4, 5 },\n+      { 4, 5 }\n+    };\n+\n+  VERIFY( umm.size() == 6 );\n+  VERIFY( umm.find(0) != umm.end() );\n+}\ndiff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/const_container.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/const_container.cc\nnew file mode 100644\nindex 000000000000..c0dcacef6388\n--- /dev/null\n+++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/const_container.cc\n@@ -0,0 +1,14 @@\n+// { dg-do compile { target c++11 } }\n+\n+#include <unordered_set>\n+\n+#include <testsuite_hooks.h>\n+\n+int main()\n+{\n+  const std::unordered_multiset<int> ums\n+    { 0, 0, 1, 1, 2, 2 };\n+\n+  VERIFY( ums.size() == 6 );\n+  VERIFY( ums.find(0) != ums.end() );\n+}\ndiff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/const_container.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/const_container.cc\nnew file mode 100644\nindex 000000000000..34d10aa7a282\n--- /dev/null\n+++ b/libstdc++-v3/testsuite/23_containers/unordered_set/const_container.cc\n@@ -0,0 +1,13 @@\n+// { dg-do compile { target c++11 } }\n+\n+#include <unordered_set>\n+\n+#include <testsuite_hooks.h>\n+\n+int main()\n+{\n+  const std::unordered_set<int> us { 0, 1, 2 };\n+\n+  VERIFY( us.size() == 3 );\n+  VERIFY( us.find(0) != us.end() );\n+}\ndiff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/mutex_association.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/mutex_association.cc\nindex ba2ede04447e..792ed455e2c6 100644\n--- a/libstdc++-v3/testsuite/23_containers/vector/debug/mutex_association.cc\n+++ b/libstdc++-v3/testsuite/23_containers/vector/debug/mutex_association.cc\n@@ -25,7 +25,7 @@ class container : public __gnu_debug::_Safe_sequence<container>\n {\n public:\n   __gnu_cxx::__mutex&\n-  get_mutex()\n+  get_mutex() const\n   { return this->_M_get_mutex(); }\n };\n \ndiff --git a/libstdc++-v3/testsuite/util/testsuite_containers.h b/libstdc++-v3/testsuite/util/testsuite_containers.h\nindex 37491a405dc0..ab0107f79e44 100644\n--- a/libstdc++-v3/testsuite/util/testsuite_containers.h\n+++ b/libstdc++-v3/testsuite/util/testsuite_containers.h\n@@ -210,6 +210,9 @@ namespace __gnu_test\n \tclit = container.cbegin(bn);\n \tassert( ++clit == container.cend(bn) );\n \n+\tclit = container.begin(bn);\n+\tassert( ++clit == container.cend(bn) );\n+\n \tassert( container.begin(bn) != container.cend(bn) );\n       }\n     };\n@@ -304,6 +307,9 @@ namespace __gnu_test\n \tassert( container.cbegin() != container.cend() );\n \tassert( container.cbegin() != container.end() );\n \tassert( container.begin() != container.cend() );\n+\n+\tauto cit = container.begin();\n+\tassert( cit == container.cbegin() );\n       }\n   };\n \n",
    "prefixes": [
        "v1",
        "1/2"
    ]
}