diff --git a/libcxx/include/__config b/libcxx/include/__config --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -86,6 +86,8 @@ // ... add new file formats here ... # endif +// ABI { + # if _LIBCPP_ABI_VERSION >= 2 // Change short string representation so that string data starts at offset 0, // improving its alignment in some cases. @@ -191,6 +193,19 @@ # define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION # endif +// Changes the iterator type of select containers (see below) to a bounded iterator that keeps track of whether it's +// within the bounds of the original container and asserts it on every dereference. +// +// ABI impact: changes the iterator type of the relevant containers. +// +// Supported containers: +// - `span`; +// - `string_view`; +// - `array`. +// #define _LIBCPP_ABI_BOUNDED_ITERATORS + +// } ABI + # define _LIBCPP_TOSTRING2(x) #x # define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) diff --git a/libcxx/include/__debug b/libcxx/include/__debug --- a/libcxx/include/__debug +++ b/libcxx/include/__debug @@ -27,8 +27,8 @@ # define _LIBCPP_DEBUG_STRICT_WEAK_ORDERING_CHECK #endif -#if defined(_LIBCPP_ENABLE_DEBUG_MODE) && !defined(_LIBCPP_DEBUG_ITERATOR_BOUNDS_CHECKING) -# define _LIBCPP_DEBUG_ITERATOR_BOUNDS_CHECKING +#if defined(_LIBCPP_ENABLE_DEBUG_MODE) && !defined(_LIBCPP_ABI_BOUNDED_ITERATORS) +# define _LIBCPP_ABI_BOUNDED_ITERATORS #endif #ifdef _LIBCPP_ENABLE_DEBUG_MODE diff --git a/libcxx/include/span b/libcxx/include/span --- a/libcxx/include/span +++ b/libcxx/include/span @@ -214,7 +214,7 @@ using const_pointer = const _Tp *; using reference = _Tp &; using const_reference = const _Tp &; -#ifdef _LIBCPP_DEBUG_ITERATOR_BOUNDS_CHECKING +#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS using iterator = __bounded_iter; #else using iterator = __wrap_iter; @@ -359,14 +359,14 @@ // [span.iter], span iterator support _LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept { -#ifdef _LIBCPP_DEBUG_ITERATOR_BOUNDS_CHECKING +#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS return std::__make_bounded_iter(data(), data(), data() + size()); #else return iterator(this, data()); #endif } _LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept { -#ifdef _LIBCPP_DEBUG_ITERATOR_BOUNDS_CHECKING +#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS return std::__make_bounded_iter(data() + size(), data(), data() + size()); #else return iterator(this, data() + size()); @@ -398,7 +398,7 @@ using const_pointer = const _Tp *; using reference = _Tp &; using const_reference = const _Tp &; -#ifdef _LIBCPP_DEBUG_ITERATOR_BOUNDS_CHECKING +#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS using iterator = __bounded_iter; #else using iterator = __wrap_iter; @@ -525,14 +525,14 @@ // [span.iter], span iterator support _LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept { -#ifdef _LIBCPP_DEBUG_ITERATOR_BOUNDS_CHECKING +#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS return std::__make_bounded_iter(data(), data(), data() + size()); #else return iterator(this, data()); #endif } _LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept { -#ifdef _LIBCPP_DEBUG_ITERATOR_BOUNDS_CHECKING +#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS return std::__make_bounded_iter(data() + size(), data(), data() + size()); #else return iterator(this, data() + size()); diff --git a/libcxx/include/string_view b/libcxx/include/string_view --- a/libcxx/include/string_view +++ b/libcxx/include/string_view @@ -274,7 +274,7 @@ using const_pointer = const _CharT*; using reference = _CharT&; using const_reference = const _CharT&; -#ifdef _LIBCPP_DEBUG_ITERATOR_BOUNDS_CHECKING +#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS using const_iterator = __bounded_iter; #else using const_iterator = const_pointer; // See [string.view.iterators] @@ -355,7 +355,7 @@ _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY const_iterator cbegin() const _NOEXCEPT { -#ifdef _LIBCPP_DEBUG_ITERATOR_BOUNDS_CHECKING +#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS return std::__make_bounded_iter(data(), data(), data() + size()); #else return __data_; @@ -364,7 +364,7 @@ _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY const_iterator cend() const _NOEXCEPT { -#ifdef _LIBCPP_DEBUG_ITERATOR_BOUNDS_CHECKING +#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS return std::__make_bounded_iter(data() + size(), data(), data() + size()); #else return __data_ + __size_;