Index: libcxx/include/__debug =================================================================== --- libcxx/include/__debug +++ libcxx/include/__debug @@ -40,7 +40,11 @@ #endif #ifndef _LIBCPP_ASSERT -# define _LIBCPP_ASSERT(x, m) ((void)0) +# ifdef _LIBCPP_HARDEN +# define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : __builtin_trap()) +# else +# define _LIBCPP_ASSERT(x, m) ((void)0) +# endif #endif #ifndef _LIBCPP_DEBUG_ASSERT # define _LIBCPP_DEBUG_ASSERT(x, m) ((void)0) Index: libcxx/include/string_view =================================================================== --- libcxx/include/string_view +++ libcxx/include/string_view @@ -278,7 +278,9 @@ // [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(size() == 0 || __pos < size(), "string_view[] index out of bounds"), __data[__pos]; + } _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY const_reference at(size_type __pos) const