From: "François Dumont" <frs.dumont@gmail.com>
To: "libstdc++@gcc.gnu.org" <libstdc++@gcc.gnu.org>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] Avoid allocator operator== in _Safe_container
Date: Mon, 9 Aug 2021 12:23:55 +0200 [thread overview]
Message-ID: <6edc763b-e463-a676-0232-7b2193fb403b@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 908 bytes --]
Some newly introduced tests in
23_containers/unordered_map/cons/default.cc revealed that we are forcing
the allocator type to have a operator==.
It can be avoided by checking allocator_traits::is_always_equal.
libstdc++: [_GLIBCXX_DEBUG] Avoid allocator operator== when always
equal
Use std::allocator_traits::is_always_equal to find out if we need
to compare
allocator instances on safe container allocator aware move constructor.
libstdc++-v3/ChangeLog:
* include/debug/safe_container.h
(_Safe_container(_Safe_container&&, const _Alloc&,
std::true_type)): New.
(_Safe_container(_Safe_container&&, const _Alloc&,
std::false_type)): New.
(_Safe_container(_Safe_container&&, const _Alloc&)): Use
latters.
Tested under Linux x86 Debug mode.
Ok to commit ?
François
[-- Attachment #2: safe_container.patch --]
[-- Type: text/x-patch, Size: 1095 bytes --]
diff --git a/libstdc++-v3/include/debug/safe_container.h b/libstdc++-v3/include/debug/safe_container.h
index d9636c29e9b..b06c33dac7e 100644
--- a/libstdc++-v3/include/debug/safe_container.h
+++ b/libstdc++-v3/include/debug/safe_container.h
@@ -57,7 +57,12 @@ namespace __gnu_debug
_Safe_container(const _Safe_container&) = default;
_Safe_container(_Safe_container&&) = default;
- _Safe_container(_Safe_container&& __x, const _Alloc& __a)
+ private:
+ _Safe_container(_Safe_container&& __x, const _Alloc& __a, std::true_type)
+ : _Safe_container()
+ { _Base::_M_swap(__x); }
+
+ _Safe_container(_Safe_container&& __x, const _Alloc& __a, std::false_type)
: _Safe_container()
{
if (__x._M_cont().get_allocator() == __a)
@@ -65,6 +70,12 @@ namespace __gnu_debug
else
__x._M_invalidate_all();
}
+
+ protected:
+ _Safe_container(_Safe_container&& __x, const _Alloc& __a)
+ : _Safe_container(std::move(__x), __a,
+ typename std::allocator_traits<_Alloc>::is_always_equal{})
+ { }
#endif
public:
next reply other threads:[~2021-08-09 10:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-09 10:23 François Dumont [this message]
2021-08-09 10:33 ` Jonathan Wakely
2021-08-09 10:34 ` Jonathan Wakely
2021-08-09 10:45 ` Jonathan Wakely
2021-08-09 11:52 ` François Dumont
2021-08-09 12:08 ` François Dumont
2021-08-09 14:24 ` Jonathan Wakely
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=6edc763b-e463-a676-0232-7b2193fb403b@gmail.com \
--to=frs.dumont@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@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).