diff options
author | Jordan Maples [MSFT] <49793787+JordanMaples@users.noreply.github.com> | 2020-02-05 23:58:49 +0300 |
---|---|---|
committer | Jordan Maples [MSFT] <49793787+JordanMaples@users.noreply.github.com> | 2020-02-05 23:58:49 +0300 |
commit | 5cf1610cfe10ca083dd9eaf14cf9a12f2cb63692 (patch) | |
tree | 132f7ec64e3534a1520959a6159951bd086c5b17 /tests/span_tests.cpp | |
parent | d7e16111377e5bf0ca9b766f4445fe4754542ed9 (diff) |
prevent overflow in size_bytes. fix compilation issue for clang 3.6 and 3.7
Diffstat (limited to 'tests/span_tests.cpp')
-rw-r--r-- | tests/span_tests.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp index ce10325..c078f3a 100644 --- a/tests/span_tests.cpp +++ b/tests/span_tests.cpp @@ -1090,6 +1090,23 @@ TEST(span_test, from_array_constructor) } } + TEST(span_test, incomparable_iterators) + { + std::set_terminate([] { + std::cerr << "Expected Death. incomparable_iterators"; + std::abort(); + }); + + int a[] = {1, 2, 3, 4}; + int b[] = {1, 2, 3, 4}; + { + span<int> s = a; + span<int> s2 = b; + EXPECT_DEATH(s.begin() == s2.begin(), deathstring); + EXPECT_DEATH(s.begin() <= s2.begin(), deathstring); + } + } + TEST(span_test, begin_end) { std::set_terminate([] { @@ -1425,8 +1442,12 @@ TEST(span_test, from_array_constructor) TEST(span_test, as_bytes) { - int a[] = {1, 2, 3, 4}; + std::set_terminate([] { + std::cerr << "Expected Death. as_bytes"; + std::abort(); + }); + int a[] = {1, 2, 3, 4}; { const span<const int> s = a; EXPECT_TRUE(s.size() == 4); @@ -1451,6 +1472,12 @@ TEST(span_test, from_array_constructor) EXPECT_TRUE(static_cast<const void*>(bs.data()) == static_cast<const void*>(s.data())); EXPECT_TRUE(bs.size() == s.size_bytes()); } + + int b[5] = {1, 2, 3, 4, 5}; + { + span<int> sp(begin(b), static_cast<size_t>(-2)); + EXPECT_DEATH((void) sp.size_bytes(), deathstring); + } } TEST(span_test, as_writeable_bytes) |