File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
tests/std/tests/GH_005236_collate_facet Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -186,8 +186,8 @@ protected:
186
186
187
187
_NODISCARD virtual long __CLR_OR_THIS_CALL do_hash(const _Elem* _First, const _Elem* _Last) const {
188
188
// 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( )));
191
191
}
192
192
193
193
private:
Original file line number Diff line number Diff line change @@ -96,6 +96,24 @@ void test_gh_5210() {
96
96
#endif // !defined(SKIP_COLLATE_TRANSFORM_TESTS)
97
97
}
98
98
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\u00DF e" ); // U+00DF LATIN SMALL LETTER SHARP S
111
+ // umlaut a collates like "ae"
112
+ test_gh_5212_compare_hash (coll, L" Kaetzchen" , L" K\u00E4 tzchen" ); // U+00E4 LATIN SMALL LETTER A WITH DIAERESIS
113
+ // umlaut A collates like "AE"
114
+ test_gh_5212_compare_hash (coll, L" AErmel" , L" \u00C4 rmel" ); // U+00C4 LATIN CAPITAL LETTER A WITH DIAERESIS
115
+ }
116
+
99
117
// GH-5236 "std::collate<wchar_t> does not respect collation order when compiled with /MD(d) /Zc:wchar_t-"
100
118
void test_gh_5236 () {
101
119
const wchar_t Ue = L' \u00DC ' ; // U+00DC LATIN CAPITAL LETTER U WITH DIARESIS
@@ -117,5 +135,6 @@ void test_gh_5236() {
117
135
118
136
int main () {
119
137
test_gh_5210 ();
138
+ test_gh_5212 ();
120
139
test_gh_5236 ();
121
140
}
You can’t perform that action at this time.
0 commit comments