|
25 | 25 | #include "check_assertion.h"
|
26 | 26 |
|
27 | 27 | int main(int, char**) {
|
28 |
| - std::array<int, 3> array{0, 1, 2}; |
| 28 | + std::array<int, 3> array{0, 1, 2}; |
29 | 29 |
|
30 |
| - auto too_large = [&] { std::span<int, 3> const s(array.data(), 4); (void)s; }; |
31 |
| - TEST_LIBCPP_ASSERT_FAILURE(too_large(), "size mismatch in span's constructor (iterator, len)"); |
| 30 | + // Input range too large (exceeds the span extent) |
| 31 | + { |
| 32 | + auto f = [&] { |
| 33 | + std::span<int, 3> const s(array.data(), 4); |
| 34 | + (void)s; |
| 35 | + }; |
| 36 | + TEST_LIBCPP_ASSERT_FAILURE(f(), "size mismatch in span's constructor (iterator, len)"); |
| 37 | + } |
32 | 38 |
|
33 |
| - auto too_small = [&] { std::span<int, 3> const s(array.data(), 2); (void)s; }; |
34 |
| - TEST_LIBCPP_ASSERT_FAILURE(too_small(), "size mismatch in span's constructor (iterator, len)"); |
| 39 | + // Input range too small (doesn't fill the span) |
| 40 | + { |
| 41 | + auto f = [&] { |
| 42 | + std::span<int, 3> const s(array.data(), 2); |
| 43 | + (void)s; |
| 44 | + }; |
| 45 | + TEST_LIBCPP_ASSERT_FAILURE(f(), "size mismatch in span's constructor (iterator, len)"); |
| 46 | + } |
35 | 47 |
|
36 |
| - return 0; |
| 48 | + // Input range is non-empty but starts with a null pointer |
| 49 | + { |
| 50 | + // static extent |
| 51 | + { |
| 52 | + auto f = [&] { |
| 53 | + int* p = nullptr; |
| 54 | + std::span<int, 3> const s(p, 3); |
| 55 | + (void)s; |
| 56 | + }; |
| 57 | + TEST_LIBCPP_ASSERT_FAILURE(f(), "passed nullptr with non-zero length in span's constructor (iterator, len)"); |
| 58 | + } |
| 59 | + |
| 60 | + // dynamic extent |
| 61 | + { |
| 62 | + auto f = [&] { |
| 63 | + int* p = nullptr; |
| 64 | + std::span<int, std::dynamic_extent> const s(p, 1); |
| 65 | + (void)s; |
| 66 | + }; |
| 67 | + TEST_LIBCPP_ASSERT_FAILURE(f(), "passed nullptr with non-zero length in span's constructor (iterator, len)"); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + return 0; |
37 | 72 | }
|
0 commit comments