|
24 | 24 | // MSVC warning C4244: 'argument': conversion from 'wchar_t' to 'const _Ty', possible loss of data |
25 | 25 | // MSVC warning C4389: '==': signed/unsigned mismatch |
26 | 26 | // ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd4242 /wd4244 /wd4389 |
| 27 | +// XFAIL: FROZEN-CXX03-HEADERS-FIXME |
27 | 28 |
|
28 | 29 | #include <algorithm> |
29 | 30 | #include <cassert> |
30 | 31 | #include <functional> |
31 | 32 | #include <vector> |
32 | 33 |
|
| 34 | +#include "sized_allocator.h" |
33 | 35 | #include "test_iterators.h" |
34 | 36 | #include "test_macros.h" |
35 | 37 | #include "type_algorithms.h" |
@@ -173,6 +175,90 @@ TEST_CONSTEXPR_CXX20 bool test() { |
173 | 175 | test_vector_bool<256>(); |
174 | 176 | } |
175 | 177 |
|
| 178 | + // Make sure std::equal behaves properly with std::vector<bool> iterators with custom size types. |
| 179 | + // See issue: https://github.com/llvm/llvm-project/issues/126369. |
| 180 | + { |
| 181 | + //// Tests for std::equal with aligned bits |
| 182 | + |
| 183 | + { // Test the first (partial) word for uint8_t |
| 184 | + using Alloc = sized_allocator<bool, std::uint8_t, std::int8_t>; |
| 185 | + std::vector<bool, Alloc> in(6, true, Alloc(1)); |
| 186 | + std::vector<bool, Alloc> expected(8, true, Alloc(1)); |
| 187 | + assert(std::equal(in.begin() + 4, in.end(), expected.begin() + 4)); |
| 188 | + } |
| 189 | + { // Test the last word for uint8_t |
| 190 | + using Alloc = sized_allocator<bool, std::uint8_t, std::int8_t>; |
| 191 | + std::vector<bool, Alloc> in(12, true, Alloc(1)); |
| 192 | + std::vector<bool, Alloc> expected(16, true, Alloc(1)); |
| 193 | + assert(std::equal(in.begin(), in.end(), expected.begin())); |
| 194 | + } |
| 195 | + { // Test middle words for uint8_t |
| 196 | + using Alloc = sized_allocator<bool, std::uint8_t, std::int8_t>; |
| 197 | + std::vector<bool, Alloc> in(24, true, Alloc(1)); |
| 198 | + std::vector<bool, Alloc> expected(29, true, Alloc(1)); |
| 199 | + assert(std::equal(in.begin(), in.end(), expected.begin())); |
| 200 | + } |
| 201 | + |
| 202 | + { // Test the first (partial) word for uint16_t |
| 203 | + using Alloc = sized_allocator<bool, std::uint16_t, std::int16_t>; |
| 204 | + std::vector<bool, Alloc> in(12, true, Alloc(1)); |
| 205 | + std::vector<bool, Alloc> expected(16, true, Alloc(1)); |
| 206 | + assert(std::equal(in.begin() + 4, in.end(), expected.begin() + 4)); |
| 207 | + } |
| 208 | + { // Test the last word for uint16_t |
| 209 | + using Alloc = sized_allocator<bool, std::uint16_t, std::int16_t>; |
| 210 | + std::vector<bool, Alloc> in(24, true, Alloc(1)); |
| 211 | + std::vector<bool, Alloc> expected(32, true, Alloc(1)); |
| 212 | + assert(std::equal(in.begin(), in.end(), expected.begin())); |
| 213 | + } |
| 214 | + { // Test middle words for uint16_t |
| 215 | + using Alloc = sized_allocator<bool, std::uint16_t, std::int16_t>; |
| 216 | + std::vector<bool, Alloc> in(48, true, Alloc(1)); |
| 217 | + std::vector<bool, Alloc> expected(55, true, Alloc(1)); |
| 218 | + assert(std::equal(in.begin(), in.end(), expected.begin())); |
| 219 | + } |
| 220 | + |
| 221 | + //// Tests for std::equal with unaligned bits |
| 222 | + |
| 223 | + { // Test the first (partial) word for uint8_t |
| 224 | + using Alloc = sized_allocator<bool, std::uint8_t, std::int8_t>; |
| 225 | + std::vector<bool, Alloc> in(6, true, Alloc(1)); |
| 226 | + std::vector<bool, Alloc> expected(8, true, Alloc(1)); |
| 227 | + assert(std::equal(in.begin() + 4, in.end(), expected.begin())); |
| 228 | + } |
| 229 | + { // Test the last word for uint8_t |
| 230 | + using Alloc = sized_allocator<bool, std::uint8_t, std::int8_t>; |
| 231 | + std::vector<bool, Alloc> in(4, true, Alloc(1)); |
| 232 | + std::vector<bool, Alloc> expected(8, true, Alloc(1)); |
| 233 | + assert(std::equal(in.begin(), in.end(), expected.begin() + 3)); |
| 234 | + } |
| 235 | + { // Test middle words for uint8_t |
| 236 | + using Alloc = sized_allocator<bool, std::uint8_t, std::int8_t>; |
| 237 | + std::vector<bool, Alloc> in(16, true, Alloc(1)); |
| 238 | + std::vector<bool, Alloc> expected(24, true, Alloc(1)); |
| 239 | + assert(std::equal(in.begin(), in.end(), expected.begin() + 4)); |
| 240 | + } |
| 241 | + |
| 242 | + { // Test the first (partial) word for uint16_t |
| 243 | + using Alloc = sized_allocator<bool, std::uint16_t, std::int16_t>; |
| 244 | + std::vector<bool, Alloc> in(12, true, Alloc(1)); |
| 245 | + std::vector<bool, Alloc> expected(16, true, Alloc(1)); |
| 246 | + assert(std::equal(in.begin() + 4, in.end(), expected.begin())); |
| 247 | + } |
| 248 | + { // Test the last word for uint16_t |
| 249 | + using Alloc = sized_allocator<bool, std::uint16_t, std::int16_t>; |
| 250 | + std::vector<bool, Alloc> in(12, true, Alloc(1)); |
| 251 | + std::vector<bool, Alloc> expected(16, true, Alloc(1)); |
| 252 | + assert(std::equal(in.begin(), in.end(), expected.begin() + 3)); |
| 253 | + } |
| 254 | + { // Test the middle words for uint16_t |
| 255 | + using Alloc = sized_allocator<bool, std::uint16_t, std::int16_t>; |
| 256 | + std::vector<bool, Alloc> in(32, true, Alloc(1)); |
| 257 | + std::vector<bool, Alloc> expected(64, true, Alloc(1)); |
| 258 | + assert(std::equal(in.begin(), in.end(), expected.begin() + 4)); |
| 259 | + } |
| 260 | + } |
| 261 | + |
176 | 262 | return true; |
177 | 263 | } |
178 | 264 |
|
|
0 commit comments