Skip to content

<xstring>: Too many enabled hash specializations #757

@CaseyCarter

Description

@CaseyCarter

Per the standard, the specializations:

template<> struct hash<string>;
template<> struct hash<u8string>;
template<> struct hash<u16string>;
template<> struct hash<u32string>;
template<> struct hash<wstring>;
template<> struct hash<pmr::string>;
template<> struct hash<pmr::u8string>;
template<> struct hash<pmr::u16string>;
template<> struct hash<pmr::u32string>;
template<> struct hash<pmr::wstring>;

template<> struct hash<string_view>;
template<> struct hash<u8string_view>;
template<> struct hash<u16string_view>;
template<> struct hash<u32string_view>;
template<> struct hash<wstring_view>;

Should be enabled, and all other specializations of hash for specializations of basic_string_view / basic_string should be disabled. We currently enable hash for all specializations of basic_string_view:

STL/stl/inc/xstring

Lines 1715 to 1724 in 852a308

// STRUCT TEMPLATE SPECIALIZATION hash FOR basic_string_view
template <class _Elem, class _Traits>
struct hash<basic_string_view<_Elem, _Traits>> {
_CXX17_DEPRECATE_ADAPTOR_TYPEDEFS typedef basic_string_view<_Elem, _Traits> _ARGUMENT_TYPE_NAME;
_CXX17_DEPRECATE_ADAPTOR_TYPEDEFS typedef size_t _RESULT_TYPE_NAME;
_NODISCARD size_t operator()(const basic_string_view<_Elem, _Traits> _Keyval) const noexcept {
return _Hash_array_representation(_Keyval.data(), _Keyval.size());
}
};

and basic_string:

STL/stl/inc/xstring

Lines 4579 to 4588 in 852a308

// STRUCT TEMPLATE SPECIALIZATION hash
template <class _Elem, class _Traits, class _Alloc>
struct hash<basic_string<_Elem, _Traits, _Alloc>> {
_CXX17_DEPRECATE_ADAPTOR_TYPEDEFS typedef basic_string<_Elem, _Traits, _Alloc> _ARGUMENT_TYPE_NAME;
_CXX17_DEPRECATE_ADAPTOR_TYPEDEFS typedef size_t _RESULT_TYPE_NAME;
_NODISCARD size_t operator()(const basic_string<_Elem, _Traits, _Alloc>& _Keyval) const noexcept {
return _Hash_array_representation(_Keyval.c_str(), _Keyval.size());
}
};

Additional Context
Skipped libcxx test

# STL bug: GH-757 <xstring>: Too many enabled hash specializations
std/strings/basic.string.hash/char_type_hash.fail.cpp FAIL
std/strings/string.view/string.view.hash/char_type.hash.fail.cpp FAIL

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions