[libc++] Add assert to check bounds in `constexpr string_view::operator[]`

Differential Revision: https://reviews.llvm.org/D88864
This commit is contained in:
Chris Palmer 2020-10-06 13:01:50 -04:00 committed by Louis Dionne
parent c6c67f643d
commit 9eff07a746
1 changed files with 3 additions and 1 deletions

View File

@ -278,7 +278,9 @@ public:
// [string.view.access], element access
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
const_reference operator[](size_type __pos) const _NOEXCEPT { return __data[__pos]; }
const_reference operator[](size_type __pos) const _NOEXCEPT {
return _LIBCPP_ASSERT(__pos < size(), "string_view[] index out of bounds"), __data[__pos];
}
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
const_reference at(size_type __pos) const