@@ -38,45 +38,51 @@ struct Test {
38
38
}
39
39
};
40
40
41
- TEST_CONSTEXPR_CXX20 void test_bit_iterator_with_custom_sized_types () {
42
- {
43
- using Alloc = sized_allocator<bool , std::uint8_t , std::int8_t >;
44
- std::vector<bool , Alloc> in (100 , true , Alloc (1 ));
45
- assert (std::count (in.begin (), in.end (), true ) == 100 );
46
- }
47
- {
48
- using Alloc = sized_allocator<bool , std::uint16_t , std::int16_t >;
49
- std::vector<bool , Alloc> in (199 , true , Alloc (1 ));
50
- assert (std::count (in.begin (), in.end (), true ) == 199 );
51
- }
52
- {
53
- using Alloc = sized_allocator<bool , std::uint32_t , std::int32_t >;
54
- std::vector<bool , Alloc> in (200 , true , Alloc (1 ));
55
- assert (std::count (in.begin (), in.end (), true ) == 200 );
56
- }
57
- {
58
- using Alloc = sized_allocator<bool , std::uint64_t , std::int64_t >;
59
- std::vector<bool , Alloc> in (257 , true , Alloc (1 ));
60
- assert (std::count (in.begin (), in.end (), true ) == 257 );
61
- }
62
- }
63
-
64
41
TEST_CONSTEXPR_CXX20 bool test () {
65
42
types::for_each (types::cpp17_input_iterator_list<const int *>(), Test ());
66
43
67
- if (TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED) {
68
- std::vector<bool > vec (256 + 64 );
69
- for (ptrdiff_t i = 0 ; i != 256 ; ++i) {
70
- for (size_t offset = 0 ; offset != 64 ; ++offset) {
71
- std::fill (vec.begin (), vec.end (), false );
72
- std::fill (vec.begin () + offset, vec.begin () + i + offset, true );
73
- assert (std::count (vec.begin () + offset, vec.begin () + offset + 256 , true ) == i);
74
- assert (std::count (vec.begin () + offset, vec.begin () + offset + 256 , false ) == 256 - i);
44
+ // Tests for std::count with std::vector<bool>::iterator optimizations.
45
+ {
46
+ { // check that vector<bool>::iterator optimization works as expected
47
+ std::vector<bool > vec (256 + 64 );
48
+ for (ptrdiff_t i = 0 ; i != 256 ; ++i) {
49
+ for (size_t offset = 0 ; offset != 64 ; ++offset) {
50
+ std::fill (vec.begin (), vec.end (), false );
51
+ std::fill (vec.begin () + offset, vec.begin () + i + offset, true );
52
+ assert (std::count (vec.begin () + offset, vec.begin () + offset + 256 , true ) == i);
53
+ assert (std::count (vec.begin () + offset, vec.begin () + offset + 256 , false ) == 256 - i);
54
+ }
75
55
}
76
56
}
77
- }
78
57
79
- test_bit_iterator_with_custom_sized_types ();
58
+ // Fix std::count for std::vector<bool> with small storage types, e.g., std::uint16_t, unsigned short.
59
+ // See https://github.com/llvm/llvm-project/issues/122528
60
+ {
61
+ using Alloc = sized_allocator<bool , std::uint8_t , std::int8_t >;
62
+ std::vector<bool , Alloc> in (100 , true , Alloc (1 ));
63
+ assert (std::count (in.begin (), in.end (), true ) == 100 );
64
+ }
65
+ {
66
+ using Alloc = sized_allocator<bool , std::uint16_t , std::int16_t >;
67
+ std::vector<bool , Alloc> in (199 , true , Alloc (1 ));
68
+ assert (std::count (in.begin (), in.end (), true ) == 199 );
69
+ }
70
+ {
71
+ using Alloc = sized_allocator<bool , unsigned short , short >;
72
+ std::vector<bool , Alloc> in (200 , true , Alloc (1 ));
73
+ assert (std::count (in.begin (), in.end (), true ) == 200 );
74
+ }
75
+ {
76
+ using Alloc = sized_allocator<bool , std::uint32_t , std::int32_t >;
77
+ std::vector<bool , Alloc> in (205 , true , Alloc (1 ));
78
+ assert (std::count (in.begin (), in.end (), true ) == 205 );
79
+ }
80
+ {
81
+ using Alloc = sized_allocator<bool , std::uint64_t , std::int64_t >;
82
+ std::vector<bool , Alloc> in (257 , true , Alloc (1 ));
83
+ assert (std::count (in.begin (), in.end (), true ) == 257 );
84
+ }
85
+ }
80
86
81
87
return true ;
82
88
}
0 commit comments