Skip to content

Commit e90e199

Browse files
1 parent bca401a commit e90e199

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

stl/inc/locale

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ protected:
186186

187187
_NODISCARD virtual long __CLR_OR_THIS_CALL do_hash(const _Elem* _First, const _Elem* _Last) const {
188188
// compute hash code for [_First, _Last)
189-
_Adl_verify_range(_First, _Last);
190-
return static_cast<long>(_Hash_array_representation(_First, static_cast<size_t>(_Last - _First)));
189+
const auto _Sortkey = collate::do_transform(_First, _Last);
190+
return static_cast<long>(_Hash_array_representation(_Sortkey.data(), _Sortkey.size()));
191191
}
192192

193193
private:

tests/std/tests/GH_005236_collate_facet/test.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,24 @@ void test_gh_5210() {
9696
#endif // !defined(SKIP_COLLATE_TRANSFORM_TESTS)
9797
}
9898

99+
void test_gh_5212_compare_hash(const collate<wchar_t>& coll, const wstring& string1, const wstring& string2) {
100+
assert(coll.hash(string1.data(), string1.data() + string1.size())
101+
== coll.hash(string2.data(), string2.data() + string2.size()));
102+
}
103+
104+
// GH-5212: std::collate_byname<_Elem>::hash() yields different hashes for strings that collate the same
105+
void test_gh_5212() {
106+
const locale loc("de-DE_phoneb");
107+
const auto& coll = use_facet<collate<wchar_t>>(loc);
108+
109+
// sharp s collates like "ss"
110+
test_gh_5212_compare_hash(coll, L"Strasse", L"Stra\u00DFe"); // U+00DF LATIN SMALL LETTER SHARP S
111+
// umlaut a collates like "ae"
112+
test_gh_5212_compare_hash(coll, L"Kaetzchen", L"K\u00E4tzchen"); // U+00E4 LATIN SMALL LETTER A WITH DIAERESIS
113+
// umlaut A collates like "AE"
114+
test_gh_5212_compare_hash(coll, L"AErmel", L"\u00C4rmel"); // U+00C4 LATIN CAPITAL LETTER A WITH DIAERESIS
115+
}
116+
99117
// GH-5236 "std::collate<wchar_t> does not respect collation order when compiled with /MD(d) /Zc:wchar_t-"
100118
void test_gh_5236() {
101119
const wchar_t Ue = L'\u00DC'; // U+00DC LATIN CAPITAL LETTER U WITH DIARESIS
@@ -117,5 +135,6 @@ void test_gh_5236() {
117135

118136
int main() {
119137
test_gh_5210();
138+
test_gh_5212();
120139
test_gh_5236();
121140
}

0 commit comments

Comments
 (0)