diff options
Diffstat (limited to 'absl/types')
-rw-r--r-- | absl/types/span.h | 2 | ||||
-rw-r--r-- | absl/types/span_test.cc | 5 |
2 files changed, 6 insertions, 1 deletions
diff --git a/absl/types/span.h b/absl/types/span.h index 3283145a..25347c63 100644 --- a/absl/types/span.h +++ b/absl/types/span.h @@ -276,7 +276,7 @@ class Span { // Returns a reference to the i'th element of this span. constexpr reference operator[](size_type i) const noexcept { // MSVC 2015 accepts this as constexpr, but not ptr_[i] - return *(data() + i); + return ABSL_ASSERT(i < size()), *(data() + i); } // Span::at() diff --git a/absl/types/span_test.cc b/absl/types/span_test.cc index 22467a0a..6ac234d3 100644 --- a/absl/types/span_test.cc +++ b/absl/types/span_test.cc @@ -232,6 +232,11 @@ TEST(IntSpan, ElementAccess) { EXPECT_EQ(s.front(), s[0]); EXPECT_EQ(s.back(), s[9]); + +#ifndef NDEBUG + EXPECT_DEATH_IF_SUPPORTED(s[-1], ""); + EXPECT_DEATH_IF_SUPPORTED(s[10], ""); +#endif } TEST(IntSpan, AtThrows) { |