public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/94805] New: variant hash algorithm is collision-prone
@ 2020-04-27 17:49 charlie at charliedyson dot net
2020-04-27 18:27 ` [Bug libstdc++/94805] " redi at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: charlie at charliedyson dot net @ 2020-04-27 17:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94805
Bug ID: 94805
Summary: variant hash algorithm is collision-prone
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: charlie at charliedyson dot net
Target Milestone: ---
The hash implementation for std::variant appears to be "index +
hash(contained_value)". This leads to collisions when working with numeric
types (e.g. a variant of various enums). Ideally a standard hash-combining
operation would be used instead of "+".
Example:
#include <variant>
#include <iostream>
enum E {ZERO, ONE};
int main ()
{
using V = std::variant<E, int>;
V v_enum = ONE;
V v_int = 0;
std::cout << std::hash<V> () (v_enum) << std::endl;
std::cout << std::hash<V> () (v_int) << std::endl;
}
Output is
1
1
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug libstdc++/94805] variant hash algorithm is collision-prone
2020-04-27 17:49 [Bug libstdc++/94805] New: variant hash algorithm is collision-prone charlie at charliedyson dot net
@ 2020-04-27 18:27 ` redi at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-27 18:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94805
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2020-04-27
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-04-27 18:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-27 17:49 [Bug libstdc++/94805] New: variant hash algorithm is collision-prone charlie at charliedyson dot net
2020-04-27 18:27 ` [Bug libstdc++/94805] " redi at gcc dot gnu.org
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).