https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104945
Bug ID: 104945
Summary: std::hash<std::uint64_t> ignores the top 32 bits when
size_t is 32 bit
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: pdimov at gmail dot com
Target Milestone: ---
A benchmark in Boost.Unordered uses uint64_t keys of the form `i << 40`:
https://github.com/boostorg/unordered/blob/33f81fd49039bccd1aa3dfd5a29ef6073b93009c/benchmark/uint64.cpp#L65
which leads to pathological behavior with std::unordered_map in 32 bit mode,
because std::hash<std::uint64_t> ignores the top 32 bits:
https://godbolt.org/z/PncKbT7aq
I'm not entirely sure whether this would be considered a bug, but decided that
it's worth reporting. Ideally, std::hash ought to take into account all bits of
the integral input, instead of truncating it to size_t.