Skip to content

Commit

Permalink
<xstring>: Restrict enabled hash specializations as required by t…
Browse files Browse the repository at this point in the history
…he standard (microsoft#2741)

Co-authored-by: Stephan T. Lavavej <[email protected]>
  • Loading branch information
2 people authored and fsb4000 committed Aug 13, 2022
1 parent 0fd830c commit 2311cd2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 35 deletions.
15 changes: 0 additions & 15 deletions stl/inc/filesystem
Original file line number Diff line number Diff line change
Expand Up @@ -211,21 +211,6 @@ namespace filesystem {
}
}

template <class>
inline constexpr bool _Is_EcharT = false;
template <>
inline constexpr bool _Is_EcharT<char> = true;
template <>
inline constexpr bool _Is_EcharT<wchar_t> = true;
#ifdef __cpp_char8_t
template <>
inline constexpr bool _Is_EcharT<char8_t> = true;
#endif // __cpp_char8_t
template <>
inline constexpr bool _Is_EcharT<char16_t> = true;
template <>
inline constexpr bool _Is_EcharT<char32_t> = true;

template <class _Ty, class = void>
inline constexpr bool _Is_Source_impl = false;

Expand Down
25 changes: 13 additions & 12 deletions stl/inc/xstring
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,12 @@ constexpr size_t _Traits_rfind_not_ch(_In_reads_(_Hay_size) const _Traits_ptr_t<
return static_cast<size_t>(-1); // no match
}

template <class _Ty>
_INLINE_VAR constexpr bool _Is_EcharT = _Is_any_of_v<_Ty, char, wchar_t,
#ifdef __cpp_char8_t
char8_t,
#endif // __cpp_char8_t
char16_t, char32_t>;

#if _HAS_CXX17
template <class _Elem, class _Traits = char_traits<_Elem>>
Expand Down Expand Up @@ -1824,12 +1830,9 @@ using u32string_view = basic_string_view<char32_t>;
using wstring_view = basic_string_view<wchar_t>;


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 {
template <class _Elem>
struct hash<basic_string_view<_Elem>> : _Conditionally_enabled_hash<basic_string_view<_Elem>, _Is_EcharT<_Elem>> {
_NODISCARD static size_t _Do_hash(const basic_string_view<_Elem> _Keyval) noexcept {
return _Hash_array_representation(_Keyval.data(), _Keyval.size());
}
};
Expand Down Expand Up @@ -5191,12 +5194,10 @@ using u8string = basic_string<char8_t, char_traits<char8_t>, allocator<char8_t>>
using u16string = basic_string<char16_t, char_traits<char16_t>, allocator<char16_t>>;
using u32string = basic_string<char32_t, char_traits<char32_t>, allocator<char32_t>>;

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 {
template <class _Elem, class _Alloc>
struct hash<basic_string<_Elem, char_traits<_Elem>, _Alloc>>
: _Conditionally_enabled_hash<basic_string<_Elem, char_traits<_Elem>, _Alloc>, _Is_EcharT<_Elem>> { // per LWG-3705
_NODISCARD static size_t _Do_hash(const basic_string<_Elem, char_traits<_Elem>, _Alloc>& _Keyval) noexcept {
return _Hash_array_representation(_Keyval.c_str(), _Keyval.size());
}
};
Expand Down
4 changes: 0 additions & 4 deletions tests/libcxx/expected_results.txt
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,6 @@ std/diagnostics/syserr/syserr.errcat/syserr.errcat.nonvirtuals/default_ctor.pass
# GH-1190 <future>: incorrectly used copy assignment instead of copy construction in set_value
std/thread/futures/futures.promise/set_value_const.pass.cpp FAIL

# 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

# GH-784 <type_traits>: aligned_storage has incorrect alignment defaults
std/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp FAIL

Expand Down
4 changes: 0 additions & 4 deletions tests/libcxx/skipped_tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,6 @@ diagnostics\syserr\syserr.errcat\syserr.errcat.nonvirtuals\default_ctor.pass.cpp
# GH-1190 <future>: incorrectly used copy assignment instead of copy construction in set_value
thread\futures\futures.promise\set_value_const.pass.cpp

# GH-757 <xstring>: Too many enabled hash specializations
strings\basic.string.hash\char_type_hash.fail.cpp
strings\string.view\string.view.hash\char_type.hash.fail.cpp

# GH-784 <type_traits>: aligned_storage has incorrect alignment defaults
utilities\meta\meta.trans\meta.trans.other\aligned_storage.pass.cpp

Expand Down

0 comments on commit 2311cd2

Please sign in to comment.