https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82262
Bug ID: 82262 Summary: std::hash<std::optional<T>>::operator() missing remove_const_t Product: gcc Version: 7.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: zhangxy at google dot com Target Milestone: --- std::hash<std::optional<T>> specialization doesn't work with const-qualified type. I think the problem is that std::remove_const_t is missing. For example, the following code will result in compiler error: #include <optional> void Foo() { std::hash<std::optional<const int>> h; std::optional<const int> o(1); size_t v = h(o); } /opt/compiler-explorer/gcc-7.2.0/include/c++/7.2.0/optional: In instantiation of 'std::size_t std::__optional_hash_call_base<_Tp, <anonymous> >::operator()(const std::optional<_Tp>&) const [with _Tp = const int; bool <anonymous> = true; std::size_t = long unsigned int]': 6 : <source>:6:19: required from here /opt/compiler-explorer/gcc-7.2.0/include/c++/7.2.0/optional:1009:37: error: could not convert '<brace-enclosed initializer list>()' from '<brace-enclosed initializer list>' to 'std::__hash_enum<const int, false>' noexcept(noexcept(hash<_Tp> {}(*__t))) ~~~~~~~~~~~~^~~~~~