public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/115285] [12/13/14/15 Regression] std::unordered_set can have duplicate value Date: Thu, 30 May 2024 10:40:07 +0000 [thread overview] Message-ID: <bug-115285-4-MaC6hdpFrN@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-115285-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115285 --- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> --- When deciding whether a key already exists in the hash set we use these overloads: template<typename _Kt> static __conditional_t< __and_<__is_nothrow_invocable<_Hash&, const key_type&>, __not_<__is_nothrow_invocable<_Hash&, _Kt>>>::value, key_type, _Kt&&> _S_forward_key(_Kt&& __k) { return std::forward<_Kt>(__k); } static const key_type& _S_forward_key(const key_type& __k) { return __k; } If the value being inserted, __k, can be hashed directly using the hash function then we return it unchanged, and then hash it. If it can't be hashed directly, we convert it to the container's key_type, which is TrimmedStr. In this case, a std::string can be hash directly without constructing a TrimmedStr (because of the questionable std::hash specialization using inheritance). So we don't convert it to TrimmedStr and just hash it directly. Hashing "foo"s and "foo "s give different hash values, so we do not consider them to be equivalent keys. While I think the code is highly questionable, the standard does say that inserting [first, last) is equivalent to insert(*first) for each iterator, and that would force an implicit conversion to value_type. So I'm not sure if the optimization to avoid temporaries (PR 96088) is actually allowed by the standard.
next prev parent reply other threads:[~2024-05-30 10:40 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-05-30 1:36 [Bug libstdc++/115285] New: std::unordered_set can have duplicate values bugs at phlexo dot com 2024-05-30 1:40 ` [Bug libstdc++/115285] " bugs at phlexo dot com 2024-05-30 1:43 ` [Bug libstdc++/115285] [13/14/15 Regression] std::unordered_set can have duplicate values since r13-1114 pinskia at gcc dot gnu.org 2024-05-30 1:46 ` pinskia at gcc dot gnu.org 2024-05-30 1:49 ` pinskia at gcc dot gnu.org 2024-05-30 1:51 ` pinskia at gcc dot gnu.org 2024-05-30 1:52 ` [Bug libstdc++/115285] [13/14/15 Regression] std::unordered_set can have duplicate value pinskia at gcc dot gnu.org 2024-05-30 1:52 ` pinskia at gcc dot gnu.org 2024-05-30 1:55 ` pinskia at gcc dot gnu.org 2024-05-30 10:09 ` [Bug libstdc++/115285] [12/13/14/15 " redi at gcc dot gnu.org 2024-05-30 10:24 ` redi at gcc dot gnu.org 2024-05-30 10:40 ` redi at gcc dot gnu.org [this message] 2024-06-20 9:15 ` rguenth at gcc dot gnu.org
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=bug-115285-4-MaC6hdpFrN@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@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: linkBe 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).