-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Add [[clang::lifetimebound]] to numerous functions in libc++ include headers #112751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add [[clang::lifetimebound]] to numerous functions in libc++ include headers #112751
Conversation
@llvm/pr-subscribers-libcxx Author: None (higher-performance) ChangesThis is a fix for #62390. These were generated via the following Perl command:
Patch is 311.01 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/112751.diff 60 Files Affected:
diff --git a/libcxx/include/__bit_reference b/libcxx/include/__bit_reference
index 22637d43974123..930062ea471b1e 100644
--- a/libcxx/include/__bit_reference
+++ b/libcxx/include/__bit_reference
@@ -609,10 +609,10 @@ struct __bit_array {
std::__construct_at(__word_ + __i, 0);
}
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator begin() {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator begin() _LIBCPP_LIFETIMEBOUND {
return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]), 0);
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator end() {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator end() _LIBCPP_LIFETIMEBOUND {
return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]) + __size_ / __bits_per_word,
static_cast<unsigned>(__size_ % __bits_per_word));
}
@@ -905,7 +905,7 @@ public:
return (__x.__seg_ - __y.__seg_) * __bits_per_word + __x.__ctz_ - __y.__ctz_;
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator[](difference_type __n) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator[](difference_type __n) const _LIBCPP_LIFETIMEBOUND {
return *(*this + __n);
}
diff --git a/libcxx/include/__chrono/tzdb_list.h b/libcxx/include/__chrono/tzdb_list.h
index 18446d9926d9dc..bb140128364f3b 100644
--- a/libcxx/include/__chrono/tzdb_list.h
+++ b/libcxx/include/__chrono/tzdb_list.h
@@ -53,15 +53,15 @@ class _LIBCPP_AVAILABILITY_TZDB tzdb_list {
using const_iterator = forward_list<tzdb>::const_iterator;
- [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const tzdb& front() const noexcept { return __front(); }
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const tzdb& front() const noexcept _LIBCPP_LIFETIMEBOUND { return __front(); }
- _LIBCPP_HIDE_FROM_ABI const_iterator erase_after(const_iterator __p) { return __erase_after(__p); }
+ _LIBCPP_HIDE_FROM_ABI const_iterator erase_after(const_iterator __p) _LIBCPP_LIFETIMEBOUND { return __erase_after(__p); }
- [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const_iterator begin() const noexcept { return __begin(); }
- [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const_iterator end() const noexcept { return __end(); }
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const_iterator begin() const noexcept _LIBCPP_LIFETIMEBOUND { return __begin(); }
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const_iterator end() const noexcept _LIBCPP_LIFETIMEBOUND { return __end(); }
- [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const noexcept { return __cbegin(); }
- [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const_iterator cend() const noexcept { return __cend(); }
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const noexcept _LIBCPP_LIFETIMEBOUND { return __cbegin(); }
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const_iterator cend() const noexcept _LIBCPP_LIFETIMEBOUND { return __cend(); }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI __impl& __implementation() { return *__impl_; }
diff --git a/libcxx/include/__expected/expected.h b/libcxx/include/__expected/expected.h
index 3d3f11967ee746..883b60008a0232 100644
--- a/libcxx/include/__expected/expected.h
+++ b/libcxx/include/__expected/expected.h
@@ -714,7 +714,7 @@ class expected : private __expected_base<_Tp, _Err> {
template <class... _Args>
requires is_nothrow_constructible_v<_Tp, _Args...>
- _LIBCPP_HIDE_FROM_ABI constexpr _Tp& emplace(_Args&&... __args) noexcept {
+ _LIBCPP_HIDE_FROM_ABI constexpr _Tp& emplace(_Args&&... __args) noexcept _LIBCPP_LIFETIMEBOUND {
this->__destroy();
this->__construct(in_place, std::forward<_Args>(__args)...);
return this->__val();
@@ -722,7 +722,7 @@ class expected : private __expected_base<_Tp, _Err> {
template <class _Up, class... _Args>
requires is_nothrow_constructible_v<_Tp, initializer_list<_Up>&, _Args...>
- _LIBCPP_HIDE_FROM_ABI constexpr _Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) noexcept {
+ _LIBCPP_HIDE_FROM_ABI constexpr _Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) noexcept _LIBCPP_LIFETIMEBOUND {
this->__destroy();
this->__construct(in_place, __il, std::forward<_Args>(__args)...);
return this->__val();
diff --git a/libcxx/include/__filesystem/directory_iterator.h b/libcxx/include/__filesystem/directory_iterator.h
index e0246d8001e195..4ba09cd42dbe7b 100644
--- a/libcxx/include/__filesystem/directory_iterator.h
+++ b/libcxx/include/__filesystem/directory_iterator.h
@@ -124,9 +124,9 @@ operator!=(const directory_iterator& __lhs, const directory_iterator& __rhs) noe
}
// enable directory_iterator range-based for statements
-inline _LIBCPP_HIDE_FROM_ABI directory_iterator begin(directory_iterator __iter) noexcept { return __iter; }
+inline _LIBCPP_HIDE_FROM_ABI directory_iterator begin(directory_iterator __iter) noexcept _LIBCPP_LIFETIMEBOUND { return __iter; }
-inline _LIBCPP_HIDE_FROM_ABI directory_iterator end(directory_iterator) noexcept { return directory_iterator(); }
+inline _LIBCPP_HIDE_FROM_ABI directory_iterator end(directory_iterator) noexcept _LIBCPP_LIFETIMEBOUND { return directory_iterator(); }
_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP
diff --git a/libcxx/include/__filesystem/path.h b/libcxx/include/__filesystem/path.h
index 2eb60810af02b5..70dea519160c55 100644
--- a/libcxx/include/__filesystem/path.h
+++ b/libcxx/include/__filesystem/path.h
@@ -864,8 +864,8 @@ class _LIBCPP_EXPORTED_FROM_ABI path {
class _LIBCPP_EXPORTED_FROM_ABI iterator;
typedef iterator const_iterator;
- iterator begin() const;
- iterator end() const;
+ iterator begin() const _LIBCPP_LIFETIMEBOUND;
+ iterator end() const _LIBCPP_LIFETIMEBOUND;
# if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
template <
diff --git a/libcxx/include/__filesystem/recursive_directory_iterator.h b/libcxx/include/__filesystem/recursive_directory_iterator.h
index caa1396eb301fc..497cae0f6e9390 100644
--- a/libcxx/include/__filesystem/recursive_directory_iterator.h
+++ b/libcxx/include/__filesystem/recursive_directory_iterator.h
@@ -133,11 +133,11 @@ operator!=(const recursive_directory_iterator& __lhs, const recursive_directory_
return !(__lhs == __rhs);
}
// enable recursive_directory_iterator range-based for statements
-inline _LIBCPP_HIDE_FROM_ABI recursive_directory_iterator begin(recursive_directory_iterator __iter) noexcept {
+inline _LIBCPP_HIDE_FROM_ABI recursive_directory_iterator begin(recursive_directory_iterator __iter) noexcept _LIBCPP_LIFETIMEBOUND {
return __iter;
}
-inline _LIBCPP_HIDE_FROM_ABI recursive_directory_iterator end(recursive_directory_iterator) noexcept {
+inline _LIBCPP_HIDE_FROM_ABI recursive_directory_iterator end(recursive_directory_iterator) noexcept _LIBCPP_LIFETIMEBOUND {
return recursive_directory_iterator();
}
diff --git a/libcxx/include/__format/format_parse_context.h b/libcxx/include/__format/format_parse_context.h
index 54c23014e7dc60..493d397bc43ffe 100644
--- a/libcxx/include/__format/format_parse_context.h
+++ b/libcxx/include/__format/format_parse_context.h
@@ -41,8 +41,8 @@ class _LIBCPP_TEMPLATE_VIS basic_format_parse_context {
basic_format_parse_context(const basic_format_parse_context&) = delete;
basic_format_parse_context& operator=(const basic_format_parse_context&) = delete;
- _LIBCPP_HIDE_FROM_ABI constexpr const_iterator begin() const noexcept { return __begin_; }
- _LIBCPP_HIDE_FROM_ABI constexpr const_iterator end() const noexcept { return __end_; }
+ _LIBCPP_HIDE_FROM_ABI constexpr const_iterator begin() const noexcept _LIBCPP_LIFETIMEBOUND { return __begin_; }
+ _LIBCPP_HIDE_FROM_ABI constexpr const_iterator end() const noexcept _LIBCPP_LIFETIMEBOUND { return __end_; }
_LIBCPP_HIDE_FROM_ABI constexpr void advance_to(const_iterator __it) { __begin_ = __it; }
_LIBCPP_HIDE_FROM_ABI constexpr size_t next_arg_id() {
diff --git a/libcxx/include/__format/formatter_floating_point.h b/libcxx/include/__format/formatter_floating_point.h
index fc95dd3f22bbe7..9e98e0e058ce04 100644
--- a/libcxx/include/__format/formatter_floating_point.h
+++ b/libcxx/include/__format/formatter_floating_point.h
@@ -183,8 +183,8 @@ class _LIBCPP_TEMPLATE_VIS __float_buffer {
_LIBCPP_HIDE_FROM_ABI __float_buffer(const __float_buffer&) = delete;
_LIBCPP_HIDE_FROM_ABI __float_buffer& operator=(const __float_buffer&) = delete;
- _LIBCPP_HIDE_FROM_ABI char* begin() const { return __begin_; }
- _LIBCPP_HIDE_FROM_ABI char* end() const { return __begin_ + __size_; }
+ _LIBCPP_HIDE_FROM_ABI char* begin() const _LIBCPP_LIFETIMEBOUND { return __begin_; }
+ _LIBCPP_HIDE_FROM_ABI char* end() const _LIBCPP_LIFETIMEBOUND { return __begin_ + __size_; }
_LIBCPP_HIDE_FROM_ABI int __precision() const { return __precision_; }
_LIBCPP_HIDE_FROM_ABI int __num_trailing_zeros() const { return __num_trailing_zeros_; }
diff --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table
index 560e873adc3846..8d93b5c324b62d 100644
--- a/libcxx/include/__hash_table
+++ b/libcxx/include/__hash_table
@@ -891,10 +891,10 @@ public:
_LIBCPP_HIDE_FROM_ABI size_type bucket_count() const _NOEXCEPT { return __bucket_list_.get_deleter().size(); }
- _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT;
- _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT;
- _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT;
- _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT;
+ _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT _LIBCPP_LIFETIMEBOUND;
+ _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT _LIBCPP_LIFETIMEBOUND;
+ _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND;
+ _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND;
template <class _Key>
_LIBCPP_HIDE_FROM_ABI size_type bucket(const _Key& __k) const {
@@ -904,15 +904,15 @@ public:
}
template <class _Key>
- _LIBCPP_HIDE_FROM_ABI iterator find(const _Key& __x);
+ _LIBCPP_HIDE_FROM_ABI iterator find(const _Key& __x) _LIBCPP_LIFETIMEBOUND;
template <class _Key>
- _LIBCPP_HIDE_FROM_ABI const_iterator find(const _Key& __x) const;
+ _LIBCPP_HIDE_FROM_ABI const_iterator find(const _Key& __x) const _LIBCPP_LIFETIMEBOUND;
typedef __hash_node_destructor<__node_allocator> _Dp;
typedef unique_ptr<__node, _Dp> __node_holder;
- _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p);
- _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last);
+ _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p) _LIBCPP_LIFETIMEBOUND;
+ _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last) _LIBCPP_LIFETIMEBOUND;
template <class _Key>
_LIBCPP_HIDE_FROM_ABI size_type __erase_unique(const _Key& __k);
template <class _Key>
@@ -958,25 +958,25 @@ public:
max_load_factor() = std::max(__mlf, load_factor());
}
- _LIBCPP_HIDE_FROM_ABI local_iterator begin(size_type __n) {
+ _LIBCPP_HIDE_FROM_ABI local_iterator begin(size_type __n) _LIBCPP_LIFETIMEBOUND {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
__n < bucket_count(), "unordered container::begin(n) called with n >= bucket_count()");
return local_iterator(__bucket_list_[__n], __n, bucket_count());
}
- _LIBCPP_HIDE_FROM_ABI local_iterator end(size_type __n) {
+ _LIBCPP_HIDE_FROM_ABI local_iterator end(size_type __n) _LIBCPP_LIFETIMEBOUND {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
__n < bucket_count(), "unordered container::end(n) called with n >= bucket_count()");
return local_iterator(nullptr, __n, bucket_count());
}
- _LIBCPP_HIDE_FROM_ABI const_local_iterator cbegin(size_type __n) const {
+ _LIBCPP_HIDE_FROM_ABI const_local_iterator cbegin(size_type __n) const _LIBCPP_LIFETIMEBOUND {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
__n < bucket_count(), "unordered container::cbegin(n) called with n >= bucket_count()");
return const_local_iterator(__bucket_list_[__n], __n, bucket_count());
}
- _LIBCPP_HIDE_FROM_ABI const_local_iterator cend(size_type __n) const {
+ _LIBCPP_HIDE_FROM_ABI const_local_iterator cend(size_type __n) const _LIBCPP_LIFETIMEBOUND {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
__n < bucket_count(), "unordered container::cend(n) called with n >= bucket_count()");
return const_local_iterator(nullptr, __n, bucket_count());
diff --git a/libcxx/include/__iterator/access.h b/libcxx/include/__iterator/access.h
index acc4f60bf697ea..82d1d4b7de1653 100644
--- a/libcxx/include/__iterator/access.h
+++ b/libcxx/include/__iterator/access.h
@@ -69,22 +69,22 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto cend(const _Cp& __c) noexcept(noexcept(std:
#else // defined(_LIBCPP_CXX03_LANG)
template <class _Cp>
-_LIBCPP_HIDE_FROM_ABI typename _Cp::iterator begin(_Cp& __c) {
+_LIBCPP_HIDE_FROM_ABI typename _Cp::iterator begin(_Cp& __c) _LIBCPP_LIFETIMEBOUND {
return __c.begin();
}
template <class _Cp>
-_LIBCPP_HIDE_FROM_ABI typename _Cp::const_iterator begin(const _Cp& __c) {
+_LIBCPP_HIDE_FROM_ABI typename _Cp::const_iterator begin(const _Cp& __c) _LIBCPP_LIFETIMEBOUND {
return __c.begin();
}
template <class _Cp>
-_LIBCPP_HIDE_FROM_ABI typename _Cp::iterator end(_Cp& __c) {
+_LIBCPP_HIDE_FROM_ABI typename _Cp::iterator end(_Cp& __c) _LIBCPP_LIFETIMEBOUND {
return __c.end();
}
template <class _Cp>
-_LIBCPP_HIDE_FROM_ABI typename _Cp::const_iterator end(const _Cp& __c) {
+_LIBCPP_HIDE_FROM_ABI typename _Cp::const_iterator end(const _Cp& __c) _LIBCPP_LIFETIMEBOUND {
return __c.end();
}
diff --git a/libcxx/include/__iterator/bounded_iter.h b/libcxx/include/__iterator/bounded_iter.h
index 5a86bd98e71940..e499e4c8bbcd12 100644
--- a/libcxx/include/__iterator/bounded_iter.h
+++ b/libcxx/include/__iterator/bounded_iter.h
@@ -118,7 +118,7 @@ struct __bounded_iter {
return std::__to_address(__current_);
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator[](difference_type __n) const _NOEXCEPT {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator[](difference_type __n) const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
__n >= __begin_ - __current_, "__bounded_iter::operator[]: Attempt to index an iterator past the start");
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
diff --git a/libcxx/include/__iterator/move_iterator.h b/libcxx/include/__iterator/move_iterator.h
index a1c53e9bd2b596..fb2bd2b8ca174b 100644
--- a/libcxx/include/__iterator/move_iterator.h
+++ b/libcxx/include/__iterator/move_iterator.h
@@ -140,7 +140,7 @@ class _LIBCPP_TEMPLATE_VIS move_iterator
_LIBCPP_HIDE_FROM_ABI constexpr _Iter base() && { return std::move(__current_); }
_LIBCPP_HIDE_FROM_ABI constexpr reference operator*() const { return ranges::iter_move(__current_); }
- _LIBCPP_HIDE_FROM_ABI constexpr reference operator[](difference_type __n) const {
+ _LIBCPP_HIDE_FROM_ABI constexpr reference operator[](difference_type __n) const _LIBCPP_LIFETIMEBOUND {
return ranges::iter_move(__current_ + __n);
}
@@ -174,7 +174,7 @@ class _LIBCPP_TEMPLATE_VIS move_iterator
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator*() const {
return static_cast<reference>(*__current_);
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator[](difference_type __n) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator[](difference_type __n) const _LIBCPP_LIFETIMEBOUND {
return static_cast<reference>(__current_[__n]);
}
diff --git a/libcxx/include/__iterator/reverse_iterator.h b/libcxx/include/__iterator/reverse_iterator.h
index 50c0f21eaa286b..6022e2abb8dc01 100644
--- a/libcxx/include/__iterator/reverse_iterator.h
+++ b/libcxx/include/__iterator/reverse_iterator.h
@@ -178,7 +178,7 @@ class _LIBCPP_TEMPLATE_VIS reverse_iterator
current += __n;
return *this;
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator[](difference_type __n) const {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference operator[](difference_type __n) const _LIBCPP_LIFETIMEBOUND {
return *(*this + __n);
}
diff --git a/libcxx/include/__iterator/wrap_iter.h b/libcxx/include/__iterator/wrap_iter.h
index 549d8ff2dbd7db..26b5e28800e68e 100644
--- a/libcxx/include/__iterator/wrap_iter.h
+++ b/libcxx/include/__iterator/wrap_iter.h
@@ -87,7 +87,7 @@ class __wrap_iter {
*this += -__n;
return *this;
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator[](difference_type __n) const _NOEXCEPT {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator[](difference_type __n) const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return __i_[__n];
}
diff --git a/libcxx/include/__mdspan/extents.h b/libcxx/include/__mdspan/extents.h
index 3d2c2771a834b4..c7fda349cf4b10 100644
--- a/libcxx/include/__mdspan/extents.h
+++ b/libcxx/include/__mdspan/extents.h
@@ -78,14 +78,14 @@ struct __static_array {
template <class _Tp, size_t _Size>
struct __possibly_empty_array {
_Tp __vals_[_Size];
- _LIBCPP_HIDE_FROM_ABI constexpr _Tp& operator[](size_t __index) { return __vals_[__index]; }
- _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& operator[](size_t __index) const { return __vals_[__index]; }
+ _LIBCPP_HIDE_FROM_ABI constexpr _Tp& operator[](size_t __index) _LIBCPP_LIFETIMEBOUND { return __vals_[__index]; }
+ _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& operator[](size_t __index) const _LIBCPP_LIFETIMEBOUND { return __vals_[__index]; }
};
template <class _Tp>
struct __possibly_empty_array<_Tp, 0> {
- _LIBCPP_HIDE_FROM_ABI constexpr _Tp& operator[](size_t) { __libcpp_unreachable(); }
- _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& operator[](size_t) const { __libcpp_unreachable(); }
+ _LIBCPP_HIDE_FROM_ABI constexpr _Tp& operator[](size_t) _LIBCPP_LIFETIMEBOUND { __libcpp_unreachable(); }
+ _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& operator[](size_t) const _LIBCPP_LIFETIMEBOUND { __libcpp_unreachable(); }
};
// ------------------------------------------------------------------
diff --git a/libcxx/include/__mdspan/mdspan.h b/libcxx/include/__mdspan/mdspan.h
index 1ff4fd4ba4a829..3f41c8ea364e6a 100644
--- a/libcxx/include/__mdspan/mdspan.h
+++ b/libcxx/include/__mdspan/mdspan.h
@@ -186,7 +186,7 @@ class mdspan {
requires((is_convertible_v<_OtherIndexTypes, index_type> && ...) &&
(is_nothrow_constructible_v<index_type, _OtherIndexTypes> && ...) &&
(sizeof...(_OtherIndexTypes) == rank()))
- _LIBCPP_HIDE_FROM_ABI constexpr reference operator[](_OtherIndexTypes... __indices) const {
+ _LIBCPP_HIDE_FROM_ABI constexpr reference operator[](_OtherIndexTypes... __indices) const _LIBCPP_LIFETIMEBOUND {
// Note the standard layouts would also check this, but user provided ones may not, so we
// check the precondition here
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__mdspan_detail::__is_multidimensional_index_in(extents(), __indices...),
diff --git a/libcxx/include/__memory/unique_ptr.h b/libcxx/include/__memory/unique_ptr.h
index 6e42ef1eaa1a3c..e547da76c487a5 100644
--- a/libcxx/include/__memory/unique_ptr.h
+++ b/libcxx/include/__memory/unique_ptr.h
@@ -275,7 +275,7 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr {
return *__ptr_;
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer operator->() const _NOEXCEPT { return __ptr_; }
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer get() const _NOEXCEPT { return __ptr_; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer get() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return __ptr_; }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 deleter_type& get_deleter() _NOEXCEPT { return __deleter_; }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const deleter_type& get_deleter() const _NOEXCEPT {
return __deleter_;
@@ -585,7 +585,7 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp>
"unique_ptr<T[]>::operator[](index): index out of range");
return __ptr_[__i];
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer get() const _NOEXCEPT { return __ptr_; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer get() const _NOEXCEPT _LIBCPP_LI...
[truncated]
|
You can test this locally with the following command:git-clang-format --diff 1a187674a116518e3c79f21df40cdb2ddf5ca312 e01e7f25f5e74458b505b68d8fdbd845954cb84c --extensions ,h,cpp -- libcxx/include/__bit_reference libcxx/include/__expected/expected.h libcxx/include/__filesystem/path.h libcxx/include/__flat_map/flat_map.h libcxx/include/__format/format_parse_context.h libcxx/include/__format/formatter_floating_point.h libcxx/include/__hash_table libcxx/include/__tree libcxx/include/__vector/vector.h libcxx/include/__vector/vector_bool.h libcxx/include/any libcxx/include/array libcxx/include/deque libcxx/include/ext/hash_map libcxx/include/ext/hash_set libcxx/include/forward_list libcxx/include/list libcxx/include/map libcxx/include/optional libcxx/include/queue libcxx/include/regex libcxx/include/set libcxx/include/string libcxx/include/unordered_map libcxx/include/unordered_set libcxx/include/variant libcxx/test/libcxx/utilities/utility/forward/lifetimebound.verify.cpp View the diff from clang-format here.diff --git a/libcxx/include/__flat_map/flat_map.h b/libcxx/include/__flat_map/flat_map.h
index 827a89d5bf..a2145292bf 100644
--- a/libcxx/include/__flat_map/flat_map.h
+++ b/libcxx/include/__flat_map/flat_map.h
@@ -527,14 +527,22 @@ public:
}
_LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() noexcept _LIBCPP_LIFETIMEBOUND { return reverse_iterator(end()); }
- _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const noexcept _LIBCPP_LIFETIMEBOUND { return const_reverse_iterator(end()); }
+ _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const noexcept _LIBCPP_LIFETIMEBOUND {
+ return const_reverse_iterator(end());
+ }
_LIBCPP_HIDE_FROM_ABI reverse_iterator rend() noexcept _LIBCPP_LIFETIMEBOUND { return reverse_iterator(begin()); }
- _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const noexcept _LIBCPP_LIFETIMEBOUND { return const_reverse_iterator(begin()); }
+ _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const noexcept _LIBCPP_LIFETIMEBOUND {
+ return const_reverse_iterator(begin());
+ }
_LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const noexcept _LIBCPP_LIFETIMEBOUND { return begin(); }
_LIBCPP_HIDE_FROM_ABI const_iterator cend() const noexcept _LIBCPP_LIFETIMEBOUND { return end(); }
- _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const noexcept _LIBCPP_LIFETIMEBOUND { return const_reverse_iterator(end()); }
- _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const noexcept _LIBCPP_LIFETIMEBOUND { return const_reverse_iterator(begin()); }
+ _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const noexcept _LIBCPP_LIFETIMEBOUND {
+ return const_reverse_iterator(end());
+ }
+ _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const noexcept _LIBCPP_LIFETIMEBOUND {
+ return const_reverse_iterator(begin());
+ }
// [flat.map.capacity], capacity
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool empty() const noexcept { return __containers_.keys.empty(); }
@@ -616,9 +624,13 @@ public:
return __try_emplace_hint(__hint, std::move(__pair.first), std::move(__pair.second)).first;
}
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __x) _LIBCPP_LIFETIMEBOUND { return emplace(__x); }
+ _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __x) _LIBCPP_LIFETIMEBOUND {
+ return emplace(__x);
+ }
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(value_type&& __x) _LIBCPP_LIFETIMEBOUND { return emplace(std::move(__x)); }
+ _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(value_type&& __x) _LIBCPP_LIFETIMEBOUND {
+ return emplace(std::move(__x));
+ }
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, const value_type& __x) _LIBCPP_LIFETIMEBOUND {
return emplace_hint(__hint, __x);
@@ -732,7 +744,8 @@ public:
template <class _Mapped>
requires is_assignable_v<mapped_type&, _Mapped> && is_constructible_v<mapped_type, _Mapped>
- _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert_or_assign(const key_type& __key, _Mapped&& __obj) _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI pair<iterator, bool>
+ insert_or_assign(const key_type& __key, _Mapped&& __obj) _LIBCPP_LIFETIMEBOUND {
return __insert_or_assign(__key, std::forward<_Mapped>(__obj));
}
@@ -751,20 +764,23 @@ public:
template <class _Mapped>
requires is_assignable_v<mapped_type&, _Mapped> && is_constructible_v<mapped_type, _Mapped>
- _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __hint, const key_type& __key, _Mapped&& __obj) _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __hint, const key_type& __key, _Mapped&& __obj)
+ _LIBCPP_LIFETIMEBOUND {
return __insert_or_assign(__hint, __key, std::forward<_Mapped>(__obj));
}
template <class _Mapped>
requires is_assignable_v<mapped_type&, _Mapped> && is_constructible_v<mapped_type, _Mapped>
- _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __hint, key_type&& __key, _Mapped&& __obj) _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __hint, key_type&& __key, _Mapped&& __obj)
+ _LIBCPP_LIFETIMEBOUND {
return __insert_or_assign(__hint, std::move(__key), std::forward<_Mapped>(__obj));
}
template <class _Kp, class _Mapped>
requires __is_compare_transparent && is_constructible_v<key_type, _Kp> && is_assignable_v<mapped_type&, _Mapped> &&
is_constructible_v<mapped_type, _Mapped>
- _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __hint, _Kp&& __key, _Mapped&& __obj) _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __hint, _Kp&& __key, _Mapped&& __obj)
+ _LIBCPP_LIFETIMEBOUND {
return __insert_or_assign(__hint, std::forward<_Kp>(__key), std::forward<_Mapped>(__obj));
}
@@ -828,7 +844,9 @@ public:
// map operations
_LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __x) _LIBCPP_LIFETIMEBOUND { return __find_impl(*this, __x); }
- _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __x) const _LIBCPP_LIFETIMEBOUND { return __find_impl(*this, __x); }
+ _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __x) const _LIBCPP_LIFETIMEBOUND {
+ return __find_impl(*this, __x);
+ }
template <class _Kp>
requires __is_compare_transparent
@@ -858,7 +876,9 @@ public:
return find(__x) != end();
}
- _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __x) _LIBCPP_LIFETIMEBOUND { return __lower_bound<iterator>(*this, __x); }
+ _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __x) _LIBCPP_LIFETIMEBOUND {
+ return __lower_bound<iterator>(*this, __x);
+ }
_LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __x) const _LIBCPP_LIFETIMEBOUND {
return __lower_bound<const_iterator>(*this, __x);
@@ -876,7 +896,9 @@ public:
return __lower_bound<const_iterator>(*this, __x);
}
- _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __x) _LIBCPP_LIFETIMEBOUND { return __upper_bound<iterator>(*this, __x); }
+ _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __x) _LIBCPP_LIFETIMEBOUND {
+ return __upper_bound<iterator>(*this, __x);
+ }
_LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const key_type& __x) const _LIBCPP_LIFETIMEBOUND {
return __upper_bound<const_iterator>(*this, __x);
@@ -898,7 +920,8 @@ public:
return __equal_range_impl(*this, __x);
}
- _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __x) const _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator>
+ equal_range(const key_type& __x) const _LIBCPP_LIFETIMEBOUND {
return __equal_range_impl(*this, __x);
}
diff --git a/libcxx/include/__vector/vector.h b/libcxx/include/__vector/vector.h
index cf0b18ebfb..2ddc3b85e7 100644
--- a/libcxx/include/__vector/vector.h
+++ b/libcxx/include/__vector/vector.h
@@ -309,22 +309,32 @@ public:
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return reverse_iterator(end());
}
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator
+ rbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return const_reverse_iterator(end());
}
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return reverse_iterator(begin());
}
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator
+ rend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return const_reverse_iterator(begin());
}
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return begin(); }
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return end(); }
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return begin();
+ }
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return end();
+ }
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator
+ crbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return rbegin();
}
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return rend(); }
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator
+ crend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return rend();
+ }
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT {
return static_cast<size_type>(this->__end_ - this->__begin_);
@@ -392,11 +402,14 @@ public:
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void pop_back();
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, const_reference __x) _LIBCPP_LIFETIMEBOUND;
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, const_reference __x)
+ _LIBCPP_LIFETIMEBOUND;
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, value_type&& __x) _LIBCPP_LIFETIMEBOUND;
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, value_type&& __x)
+ _LIBCPP_LIFETIMEBOUND;
template <class... _Args>
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __position, _Args&&... __args) _LIBCPP_LIFETIMEBOUND;
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __position, _Args&&... __args)
+ _LIBCPP_LIFETIMEBOUND;
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
insert(const_iterator __position, size_type __n, const_reference __x) _LIBCPP_LIFETIMEBOUND;
@@ -410,7 +423,8 @@ public:
#if _LIBCPP_STD_VER >= 23
template <_ContainerCompatibleRange<_Tp> _Range>
- _LIBCPP_HIDE_FROM_ABI constexpr iterator insert_range(const_iterator __position, _Range&& __range) _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI constexpr iterator
+ insert_range(const_iterator __position, _Range&& __range) _LIBCPP_LIFETIMEBOUND {
if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
auto __n = static_cast<size_type>(ranges::distance(__range));
return __insert_with_size(__position, ranges::begin(__range), ranges::end(__range), __n);
@@ -437,7 +451,8 @@ public:
#endif
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __position) _LIBCPP_LIFETIMEBOUND;
- _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last) _LIBCPP_LIFETIMEBOUND;
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last)
+ _LIBCPP_LIFETIMEBOUND;
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT {
size_type __old_size = size();
diff --git a/libcxx/include/__vector/vector_bool.h b/libcxx/include/__vector/vector_bool.h
index cfea1e3988..cc2c23d0d0 100644
--- a/libcxx/include/__vector/vector_bool.h
+++ b/libcxx/include/__vector/vector_bool.h
@@ -254,9 +254,15 @@ public:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void reserve(size_type __n);
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void shrink_to_fit() _NOEXCEPT;
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator begin() _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return __make_iter(0); }
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator begin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return __make_iter(0); }
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator end() _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return __make_iter(__size_); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator begin() _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return __make_iter(0);
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator begin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return __make_iter(0);
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator end() _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return __make_iter(__size_);
+ }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator end() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return __make_iter(__size_);
}
@@ -264,24 +270,32 @@ public:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reverse_iterator rbegin() _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return reverse_iterator(end());
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator rbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator
+ rbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return const_reverse_iterator(end());
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reverse_iterator rend() _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return reverse_iterator(begin());
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator rend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator
+ rend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return const_reverse_iterator(begin());
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator cbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return __make_iter(0); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator cbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return __make_iter(0);
+ }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator cend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return __make_iter(__size_);
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator crbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator
+ crbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return rbegin();
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator crend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return rend(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator
+ crend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return rend();
+ }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator[](size_type __n) { return __make_ref(__n); }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference operator[](size_type __n) const {
@@ -291,9 +305,15 @@ public:
_LIBCPP_HIDE_FROM_ABI const_reference at(size_type __n) const _LIBCPP_LIFETIMEBOUND;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference front() _LIBCPP_LIFETIMEBOUND { return __make_ref(0); }
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference front() const _LIBCPP_LIFETIMEBOUND { return __make_ref(0); }
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference back() _LIBCPP_LIFETIMEBOUND { return __make_ref(__size_ - 1); }
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference back() const _LIBCPP_LIFETIMEBOUND { return __make_ref(__size_ - 1); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference front() const _LIBCPP_LIFETIMEBOUND {
+ return __make_ref(0);
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference back() _LIBCPP_LIFETIMEBOUND {
+ return __make_ref(__size_ - 1);
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference back() const _LIBCPP_LIFETIMEBOUND {
+ return __make_ref(__size_ - 1);
+ }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void push_back(const value_type& __x);
#if _LIBCPP_STD_VER >= 14
@@ -322,12 +342,14 @@ public:
#if _LIBCPP_STD_VER >= 14
template <class... _Args>
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator emplace(const_iterator __position, _Args&&... __args) _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator emplace(const_iterator __position, _Args&&... __args)
+ _LIBCPP_LIFETIMEBOUND {
return insert(__position, value_type(std::forward<_Args>(__args)...));
}
#endif
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __position, const value_type& __x) _LIBCPP_LIFETIMEBOUND;
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __position, const value_type& __x)
+ _LIBCPP_LIFETIMEBOUND;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
insert(const_iterator __position, size_type __n, const value_type& __x) _LIBCPP_LIFETIMEBOUND;
template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
@@ -339,7 +361,8 @@ public:
#if _LIBCPP_STD_VER >= 23
template <_ContainerCompatibleRange<bool> _Range>
- _LIBCPP_HIDE_FROM_ABI constexpr iterator insert_range(const_iterator __position, _Range&& __range) _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI constexpr iterator
+ insert_range(const_iterator __position, _Range&& __range) _LIBCPP_LIFETIMEBOUND {
if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
auto __n = static_cast<size_type>(ranges::distance(__range));
return __insert_with_size(__position, ranges::begin(__range), ranges::end(__range), __n);
@@ -358,7 +381,8 @@ public:
#endif
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __position) _LIBCPP_LIFETIMEBOUND;
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __first, const_iterator __last) _LIBCPP_LIFETIMEBOUND;
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __first, const_iterator __last)
+ _LIBCPP_LIFETIMEBOUND;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void clear() _NOEXCEPT { __size_ = 0; }
diff --git a/libcxx/include/array b/libcxx/include/array
index 5c3d5ca38f..d435aca87d 100644
--- a/libcxx/include/array
+++ b/libcxx/include/array
@@ -202,11 +202,15 @@ struct _LIBCPP_TEMPLATE_VIS array {
}
// iterators:
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator begin() _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return iterator(data()); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator begin() _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return iterator(data());
+ }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator begin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return const_iterator(data());
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator end() _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return iterator(data() + _Size); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator end() _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return iterator(data() + _Size);
+ }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator end() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return const_iterator(data() + _Size);
}
@@ -214,22 +218,32 @@ struct _LIBCPP_TEMPLATE_VIS array {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rbegin() _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return reverse_iterator(end());
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator rbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator
+ rbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return const_reverse_iterator(end());
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rend() _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return reverse_iterator(begin());
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator rend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator
+ rend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return const_reverse_iterator(begin());
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return begin(); }
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return end(); }
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator crbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return begin();
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return end();
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator
+ crbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return rbegin();
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator crend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return rend(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator
+ crend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return rend();
+ }
// capacity:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT { return _Size; }
@@ -258,15 +272,25 @@ struct _LIBCPP_TEMPLATE_VIS array {
return __elems_[__n];
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference front() _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return (*this)[0]; }
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference front() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return (*this)[0]; }
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference back() _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return (*this)[_Size - 1]; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference front() _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return (*this)[0];
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference front() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return (*this)[0];
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reference back() _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return (*this)[_Size - 1];
+ }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const_reference back() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return (*this)[_Size - 1];
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 value_type* data() _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return __elems_; }
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const value_type* data() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return __elems_; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 value_type* data() _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return __elems_;
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const value_type* data() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return __elems_;
+ }
};
template <class _Tp>
@@ -297,8 +321,12 @@ struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> {
};
_ALIGNAS_TYPE(_ArrayInStructT) _EmptyType __elems_[sizeof(_ArrayInStructT)];
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 value_type* data() _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return nullptr; }
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const value_type* data() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return nullptr; }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 value_type* data() _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return nullptr;
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const value_type* data() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return nullptr;
+ }
// No explicit construct/copy/destroy for aggregate type
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void fill(const value_type&) {
@@ -310,11 +338,15 @@ struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> {
}
// iterators:
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator begin() _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return iterator(data()); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator begin() _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return iterator(data());
+ }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator begin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return const_iterator(data());
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator end() _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return iterator(data()); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 iterator end() _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return iterator(data());
+ }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator end() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return const_iterator(data());
}
@@ -322,22 +354,32 @@ struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rbegin() _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return reverse_iterator(end());
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator rbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator
+ rbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return const_reverse_iterator(end());
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 reverse_iterator rend() _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return reverse_iterator(begin());
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator rend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator
+ rend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return const_reverse_iterator(begin());
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return begin(); }
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return end(); }
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator crbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return begin();
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_iterator cend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return end();
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator
+ crbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return rbegin();
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator crend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return rend(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 const_reverse_iterator
+ crend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return rend();
+ }
// capacity:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT { return 0; }
diff --git a/libcxx/include/string b/libcxx/include/string
index 6895c570bc..66bc21cd89 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -1267,22 +1267,32 @@ public:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reverse_iterator rbegin() _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return reverse_iterator(end());
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator rbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator
+ rbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return const_reverse_iterator(end());
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reverse_iterator rend() _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return reverse_iterator(begin());
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator rend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator
+ rend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return const_reverse_iterator(begin());
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator cbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return begin(); }
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator cend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return end(); }
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator crbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator cbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return begin();
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator cend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return end();
+ }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator
+ crbegin() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return rbegin();
}
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator crend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return rend(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator
+ crend() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return rend();
+ }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type size() const _NOEXCEPT {
return __is_long() ? __get_long_size() : __get_short_size();
@@ -1566,7 +1576,8 @@ public:
#if _LIBCPP_STD_VER >= 23
template <_ContainerCompatibleRange<_CharT> _Range>
- _LIBCPP_HIDE_FROM_ABI constexpr iterator insert_range(const_iterator __position, _Range&& __range) _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI constexpr iterator
+ insert_range(const_iterator __position, _Range&& __range) _LIBCPP_LIFETIMEBOUND {
if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
auto __n = static_cast<size_type>(ranges::distance(__range));
return __insert_with_size(__position, ranges::begin(__range), ranges::end(__range), __n);
@@ -1602,7 +1613,8 @@ public:
_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& erase(size_type __pos = 0, size_type __n = npos);
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __pos) _LIBCPP_LIFETIMEBOUND;
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __first, const_iterator __last) _LIBCPP_LIFETIMEBOUND;
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __first, const_iterator __last)
+ _LIBCPP_LIFETIMEBOUND;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string&
replace(size_type __pos1, size_type __n1, const basic_string& __str) {
@@ -1703,7 +1715,9 @@ public:
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>);
#endif
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const value_type* c_str() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND { return data(); }
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const value_type* c_str() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
+ return data();
+ }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const value_type* data() const _NOEXCEPT _LIBCPP_LIFETIMEBOUND {
return std::__to_address(__get_pointer());
}
diff --git a/libcxx/include/variant b/libcxx/include/variant
index a486e4e0d1..1528efae19 100644
--- a/libcxx/include/variant
+++ b/libcxx/include/variant
@@ -1264,7 +1264,8 @@ public:
enable_if_t<(_Ip < sizeof...(_Types)), int> = 0,
class _Tp = variant_alternative_t<_Ip, variant<_Types...>>,
enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>, int> = 0>
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp&
+ emplace(initializer_list<_Up> __il, _Args&&... __args) _LIBCPP_LIFETIMEBOUND {
return __impl_.template __emplace<_Ip>(__il, std::forward<_Args>(__args)...);
}
@@ -1281,7 +1282,8 @@ public:
class... _Args,
size_t _Ip = __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value,
enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>, int> = 0>
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) _LIBCPP_LIFETIMEBOUND {
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp&
+ emplace(initializer_list<_Up> __il, _Args&&... __args) _LIBCPP_LIFETIMEBOUND {
return __impl_.template __emplace<_Ip>(__il, std::forward<_Args>(__args)...);
}
|
14723c9
to
1bdd76e
Compare
994e33e
to
351eff4
Compare
I think this could be interesting. Could you add a description of the benefit of this change? I know the linked issue explains it a bit, but it's good to have PRs be self-standing. Could you also add a couple of tests showing what kind of scenarios we're now diagnosing that we were not diagnosing before? That would make the benefits of this change more concrete. In #59900 (comment), @zygoloid mentioned that Clang was now inferring the attribute on some libc++ functions. Does it do that by hardcoding the names of some libc++ functions, or is there some other "intelligent" mechanism that it's using to do that? If the latter, it would be good to understand what it's doing to determine whether the additional attributes in this patch should be hardcoded in libc++ or done via Clang. At a glance, I'd much rather be explicit about these attributes inside libc++ than magically have the compiler annotate our declarations. CC @egorzhdan @Xazax-hun for awareness |
For functions that clang models as "library builtins" (which covers quite a few C standard library functions as well as a handful of C++ standard library functions), it also has a list of attributes it implicitly adds to those functions. This list is hardcoded:
In addition, it looks like we now have some custom logic to recognize
I think the It should be at worst harmless for the library to repeat an annotation that the compiler was going to infer anyway, so it seems reasonable to me for libc++ to be explicit about this, even if that means repeating an attribute. |
Thanks a lot for the breakdown @zygoloid! I think I agree with where you draw the line, i.e. As far as this draft PR goes, I think I agree with the approach which is to simply slap the attribute to declarations in libc++ that can benefit from it. I'd like to better understand what are the benefits of doing that and how far we want to go down this rabbit hole, but assuming there are diagnostics improvements to be had, I think this is something worth exploring. |
I believe the reason for the inference to be in the compiler so Clang can emit these diagnostics for other standard library implementations like libstdc++ and Microsoft's implementation. I think there is some value in detecting common cases of dangling on all platforms with all standard library implementations (I believe clang defaults to non-libc++ standard libraries on some platforms). That being said, I definitely think it makes sense to annotate the libraries, but I also think there is value in trying to make these diagnostics work for a wide range of our users. Alternatively, I could imagine Clang shipping an APINotes file for the standard libraries and loading lifetimebound annotations from that file in case the library is not annotated.
Some example diagnostics are here: https://github.com/llvm/llvm-project/blob/main/clang/test/SemaCXX/attr-lifetimebound.cpp |
351eff4
to
61c221c
Compare
Done.
Done. |
Anybody know why my tests keep getting canceled? I'm seeing errors like:
Also, while I'm asking this - is there a way to clang-format the code locally without having to build things? |
I am usually using |
3cfef11
to
e2afb0b
Compare
I seem to be encountering a strange situation where this code gives a dangling reference error when I annotate #include <string_view>
#include <vector>
std::string_view foo() {
std::vector<std::string_view> v(1);
return v[0];
} This doesn't trigger if I attempt to mimic Anybody know what is going on? |
There was an unrelated build error which was probably fixed by commit 75252e2. Unfortunately, it was landed a few minutes after the latest rebasing in this PR. Would you mind to rebase the branch again? |
This looks like a bug in Clang's lifetime analysis when class [[gsl::Pointer]] FooPointer {};
template<typename T>
class [[gsl::Owner]] Container {
public:
const T& get() const [[clang::lifetimebound]];
};
FooPointer abc2() {
Container<FooPointer> foo;
return foo.get(); // Clang emits a return-stack-address warning on `foo`.
} https://godbolt.org/z/ffYjPa7vs, |
Ah wow, thanks for isolating that. It feels like the |
Taking a closer look, it seems there's a bug in how the analyzer processes GSL pointers:
In the specific case of
One possible fix is to do the bailout if FooPointer abc3() {
Container<FooOwner> foo;
return foo.get(); // return-stack-address warning on `foo`.
} |
#114044 is a draft fix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I like this as a general direction. I find it unfortunate that we have to add so many verbose annotations, but that's how attributes work and I don't see a better way of doing this, so that's not a blocker IMO. The annotations are all very mechanical so while they add visual clutter, they at least don't add complexity.
I think this is worth it given the diagnostics we're getting. You should make this a non-draft when you're ready to get other people's view on the change.
libcxx/test/support/test_macros.h
Outdated
@@ -10,6 +10,8 @@ | |||
#ifndef SUPPORT_TEST_MACROS_HPP | |||
#define SUPPORT_TEST_MACROS_HPP | |||
|
|||
#pragma clang diagnostic warning "-Wdangling" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was due to deliberate dangling inside some of the tests, which caused CI to terminate prematurely (I believe in libcxx/test/std/containers/views/views.span/span.cons/array.pass.cpp
).
I figured checking this inside tests didn't make much sense, so I demoted it to a warning to get CI going. I'm not sure how you'd like it to be handled long-term.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to make CI just warn on this inside tests? I'm not familiar with the build internals so if you could tell me what change to make that would be ideal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have more details about what exactly was dangling? That seems suspicious to me, since we should never have UB in our tests. It would be possible to demote this to a warning, but I don't think we want to -- IMO the test suite did the right thing by making this an error cause we should probably be fixing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was it that part in libcxx/test/std/containers/views/views.span/span.cons/array.pass.cpp
:
std::span<const int> s5 = {{1,2}};
#if TEST_STD_VER >= 26
std::span<const int, 2> s6({1, 2});
#else
std::span<const int, 2> s6 = {{1,2}};
#endif
assert(s5.size() == 2); // and it dangles
assert(s6.size() == 2); // and it dangles
I don't understand how that would trigger -Wdangling
after this patch though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no UB.
s5.size()
is OK, but s5[0]
is not. But lifetimebound isn't granular enough to say "this method is OK on a dangling object but that method is not", so we have to make it all-or-nothing. In this case, we say that the entire view (i.e. span) is bad even if the size is OK to query, because it's almost always bad usage in practice.
Note that this isn't any different from raw pointers, because this is OK:
char* p = std::string(...).data();
and this is not:
char* p = std::string(...).data();
p[0];
again, lifetimebound doesn't provide a way to distinguish these, so we just say both of them are bad, because it's a code smell (and fragile code) to have a dangling pointer to potentially-deallocated memory regardless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had trouble digging up the CI error I got, so I just updated the PR to remove this edit. Let's see if we still get failures -- I don't recall which annotation would've caused this specifically.
@@ -25,4 +26,10 @@ void func() { | |||
#if TEST_STD_VER >= 23 | |||
auto&& v5 = std::forward_like<int&&>(int{}); // expected-warning {{temporary bound to local reference 'v5' will be destroyed at the end of the full-expression}} | |||
#endif | |||
|
|||
// expected-warning@+1 {{temporary whose address is used as value of local variable 'v6' will be destroyed at the end of the full-expression}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to move forward with the patch, we'd need coverage for all the methods we're annotating. I don't think it makes sense to do it in this file since this one is only for std::forward
and related functions. Perhaps one test for each container we're adding it to (which would cover all the methods marked as lifetimebound
for that container) is best.
90b970c
to
9d8ab76
Compare
…notations in libc++, and avoid erroring on lifetimebound warnings in libcxx test code
9d8ab76
to
e01e7f2
Compare
The lifetime analyzer processes GSL pointers: - when encountering a constructor for a `gsl::pointer`, the analyzer continues traversing the constructor argument, regardless of whether the parameter has a `lifetimebound` annotation. This aims to catch cases where a GSL pointer is constructed from a GSL owner, either directly (e.g., `FooPointer(FooOwner)`) or through a chain of GSL pointers (e.g., `FooPointer(FooPointer(FooOwner))`); - When a temporary object is reported in the callback, the analyzer has heuristics to exclude non-owner types, aiming to avoid false positives (like `FooPointer(FooPointer())`). In the problematic case (discovered in #112751 (comment)) of `return foo.get();`: - When the analyzer reports the local object `foo`, the `Path` is `[GslPointerInit, Lifetimebound]`. - The `Path` goes through [`pathOnlyHandlesGslPointer`](https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/CheckExprLifetime.cpp#L1136) and isn’t filtered out by the [[heuristics]](because `foo` is an owner type), the analyzer treats it as the `FooPointer(FooOwner())` scenario, thus triggering a diagnostic. Filtering out base on the object 'foo' is wrong, because the GSLPointer is constructed from the return result of the `foo.get()`. The patch fixes this by teaching the heuristic to use the return result (only `const GSLOwner&` is considered) of the lifetimebound annotated function.
UPDATE: this bug is fixed in #114044, this PR should be unblocked with the trunk clang. |
Is this something you are looking into landing for the 20.x release? If that is the case, there are only a couple of days left before branching. |
@Xazax-hun nope, thanks for asking! |
Hey, any news here? Do you plan to merge this? |
Hey - nope no plans currently. I'll close it. |
Could you elaborate a bit on this? Did you run into any blockers? Or was this something that turned out to be not useful? Do you happen to have this change internally? |
To be honest, I just haven't found the bandwidth to add coverage for all the functions like I was being asked to do in the review. I had automated most of the creation of this PR, but addressing that required a ton of manual modification. It was a significant speed bump, which made me prioritize other tasks. |
I can also add to this that I cherry-picked some of these changes into the Yandex codebase (very large mostly C++ monorepo with It seems that in general LLVM is pursuing a slightly different path of adding lifetimebound metadata within compiler logic, instead of within the libc++ source code, see for example this PR (which is already included in the latest release): #103716 |
Is this with a recent compiler? Could you open some tickets with some reproducers? That would be really useful to drive these annotations forward. |
Not quite, we're on clang I'm aware that there were lots of related changes in clang 20. Once we get to that version I'm happy to re-run the checks and report back, right now it might be too noisy. |
Ah that's great to know. By any chance would you be able to share some examples(s) of the kinds of false positives you're saying here? Simply the syntax of the line of the call site is likely enough (and you can of course obfuscate the names), it might not be necessary for it to compile for us to be able to tell what the cause is. I'm mainly wondering if these are known limitations (e.g., you have a dangling view but only query its size) or if they're unintended ones. |
This is a fix for #62390 and supersedes #112614.
Adds
[[clang::lifetimebound]]
to numerous methods such asback()
,begin()
,data()
,emplace_back()
,find()
,insert()
,operator[]
, etc., since all of their outputs require the container/owner to be alive for validity. It allows analyzing many more cases withlifetimebound
, such as:The changes were generated via the following Perl command: