[libcxx-commits] [libcxx] [libc++] Simplify the implementation of std::hash (PR #140407)
Konstantin Varlamov via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Aug 15 13:39:23 PDT 2025
var-const wrote:
@philnik777 I think this patch might have introduced a regression. Consider ([Godbolt link](https://godbolt.org/z/xb8bGYM98)):
```cpp
std::hash<const int> h;
```
Before this patch, this would fail to compile (aligned with the other implementations), but with this patch we become more permissive and start accepting this code (which can e.g. make previously valid SFINAE no longer work). If I'm reading the [Standard](https://eel.is/c++draft/unord.hash#2) correctly, no specialization is defined for non-cv-qualified types, so the previous behavior was correct:
> Each specialization of hash is either enabled or disabled, as described below.
>
> Each header that declares the template `hash` provides enabled specializations of `hash` for `nullptr_t` and all **cv-unqualified** arithmetic, enumeration, and pointer types. For any type `Key` for which neither the library nor the user provides an explicit or partial specialization of the class template `hash`, `hash<Key>` is disabled.
Can we make a fix for this for the upcoming release? (cc @ldionne)
https://github.com/llvm/llvm-project/pull/140407
More information about the libcxx-commits
mailing list