Skip to content

Commit 2311cd2

Browse files
frederick-vs-jaStephanTLavavej
authored andcommitted
<xstring>: Restrict enabled hash specializations as required by the standard (microsoft#2741)
Co-authored-by: Stephan T. Lavavej <[email protected]>
1 parent 0fd830c commit 2311cd2

File tree

4 files changed

+13
-35
lines changed

4 files changed

+13
-35
lines changed

stl/inc/filesystem

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -211,21 +211,6 @@ namespace filesystem {
211211
}
212212
}
213213

214-
template <class>
215-
inline constexpr bool _Is_EcharT = false;
216-
template <>
217-
inline constexpr bool _Is_EcharT<char> = true;
218-
template <>
219-
inline constexpr bool _Is_EcharT<wchar_t> = true;
220-
#ifdef __cpp_char8_t
221-
template <>
222-
inline constexpr bool _Is_EcharT<char8_t> = true;
223-
#endif // __cpp_char8_t
224-
template <>
225-
inline constexpr bool _Is_EcharT<char16_t> = true;
226-
template <>
227-
inline constexpr bool _Is_EcharT<char32_t> = true;
228-
229214
template <class _Ty, class = void>
230215
inline constexpr bool _Is_Source_impl = false;
231216

stl/inc/xstring

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,12 @@ constexpr size_t _Traits_rfind_not_ch(_In_reads_(_Hay_size) const _Traits_ptr_t<
917917
return static_cast<size_t>(-1); // no match
918918
}
919919

920+
template <class _Ty>
921+
_INLINE_VAR constexpr bool _Is_EcharT = _Is_any_of_v<_Ty, char, wchar_t,
922+
#ifdef __cpp_char8_t
923+
char8_t,
924+
#endif // __cpp_char8_t
925+
char16_t, char32_t>;
920926

921927
#if _HAS_CXX17
922928
template <class _Elem, class _Traits = char_traits<_Elem>>
@@ -1824,12 +1830,9 @@ using u32string_view = basic_string_view<char32_t>;
18241830
using wstring_view = basic_string_view<wchar_t>;
18251831

18261832

1827-
template <class _Elem, class _Traits>
1828-
struct hash<basic_string_view<_Elem, _Traits>> {
1829-
_CXX17_DEPRECATE_ADAPTOR_TYPEDEFS typedef basic_string_view<_Elem, _Traits> _ARGUMENT_TYPE_NAME;
1830-
_CXX17_DEPRECATE_ADAPTOR_TYPEDEFS typedef size_t _RESULT_TYPE_NAME;
1831-
1832-
_NODISCARD size_t operator()(const basic_string_view<_Elem, _Traits> _Keyval) const noexcept {
1833+
template <class _Elem>
1834+
struct hash<basic_string_view<_Elem>> : _Conditionally_enabled_hash<basic_string_view<_Elem>, _Is_EcharT<_Elem>> {
1835+
_NODISCARD static size_t _Do_hash(const basic_string_view<_Elem> _Keyval) noexcept {
18331836
return _Hash_array_representation(_Keyval.data(), _Keyval.size());
18341837
}
18351838
};
@@ -5191,12 +5194,10 @@ using u8string = basic_string<char8_t, char_traits<char8_t>, allocator<char8_t>>
51915194
using u16string = basic_string<char16_t, char_traits<char16_t>, allocator<char16_t>>;
51925195
using u32string = basic_string<char32_t, char_traits<char32_t>, allocator<char32_t>>;
51935196

5194-
template <class _Elem, class _Traits, class _Alloc>
5195-
struct hash<basic_string<_Elem, _Traits, _Alloc>> {
5196-
_CXX17_DEPRECATE_ADAPTOR_TYPEDEFS typedef basic_string<_Elem, _Traits, _Alloc> _ARGUMENT_TYPE_NAME;
5197-
_CXX17_DEPRECATE_ADAPTOR_TYPEDEFS typedef size_t _RESULT_TYPE_NAME;
5198-
5199-
_NODISCARD size_t operator()(const basic_string<_Elem, _Traits, _Alloc>& _Keyval) const noexcept {
5197+
template <class _Elem, class _Alloc>
5198+
struct hash<basic_string<_Elem, char_traits<_Elem>, _Alloc>>
5199+
: _Conditionally_enabled_hash<basic_string<_Elem, char_traits<_Elem>, _Alloc>, _Is_EcharT<_Elem>> { // per LWG-3705
5200+
_NODISCARD static size_t _Do_hash(const basic_string<_Elem, char_traits<_Elem>, _Alloc>& _Keyval) noexcept {
52005201
return _Hash_array_representation(_Keyval.c_str(), _Keyval.size());
52015202
}
52025203
};

tests/libcxx/expected_results.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,6 @@ std/diagnostics/syserr/syserr.errcat/syserr.errcat.nonvirtuals/default_ctor.pass
412412
# GH-1190 <future>: incorrectly used copy assignment instead of copy construction in set_value
413413
std/thread/futures/futures.promise/set_value_const.pass.cpp FAIL
414414

415-
# GH-757 <xstring>: Too many enabled hash specializations
416-
std/strings/basic.string.hash/char_type_hash.fail.cpp FAIL
417-
std/strings/string.view/string.view.hash/char_type.hash.fail.cpp FAIL
418-
419415
# GH-784 <type_traits>: aligned_storage has incorrect alignment defaults
420416
std/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp FAIL
421417

tests/libcxx/skipped_tests.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,6 @@ diagnostics\syserr\syserr.errcat\syserr.errcat.nonvirtuals\default_ctor.pass.cpp
412412
# GH-1190 <future>: incorrectly used copy assignment instead of copy construction in set_value
413413
thread\futures\futures.promise\set_value_const.pass.cpp
414414

415-
# GH-757 <xstring>: Too many enabled hash specializations
416-
strings\basic.string.hash\char_type_hash.fail.cpp
417-
strings\string.view\string.view.hash\char_type.hash.fail.cpp
418-
419415
# GH-784 <type_traits>: aligned_storage has incorrect alignment defaults
420416
utilities\meta\meta.trans\meta.trans.other\aligned_storage.pass.cpp
421417

0 commit comments

Comments
 (0)