[libcxx-commits] [libcxx] Add [[clang::lifetimebound]] to numerous functions in libc++ include headers (PR #112751)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Oct 17 10:26:45 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: None (higher-performance)

<details>
<summary>Changes</summary>

This is a fix for #<!-- -->62390.

These were generated via the following Perl command:
```
find libcxx/include -xdev -type f -exec perl -0777 -pi -e 's/((?:(?:iterator|reference|[*&])(?:(?:,\s+bool)?>)?\s+(?:c?(?:after_|before_)?(?:begin|end)|front|back|find|lower_bound|upper_bound|equal_range|(?:emplace|erase|insert|operator\[\]|value)(?:_\w*)?)|pointer (?:data|get)|operator\s+__self_view)[(][^{()};]*[)](?:(?:noexcept|requires)(?:\s*[(](?:[^()]*|[^()]*[(][^()]*[)][^()]*)[)])?|\w+|\s+\b)*)(\s*)(\{|;)/$1 _LIBCPP_LIFETIMEBOUND$2$3/g' '{}' \+
```

---

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:

- (modified) libcxx/include/__bit_reference (+3-3) 
- (modified) libcxx/include/__chrono/tzdb_list.h (+6-6) 
- (modified) libcxx/include/__expected/expected.h (+2-2) 
- (modified) libcxx/include/__filesystem/directory_iterator.h (+2-2) 
- (modified) libcxx/include/__filesystem/path.h (+2-2) 
- (modified) libcxx/include/__filesystem/recursive_directory_iterator.h (+2-2) 
- (modified) libcxx/include/__format/format_parse_context.h (+2-2) 
- (modified) libcxx/include/__format/formatter_floating_point.h (+2-2) 
- (modified) libcxx/include/__hash_table (+12-12) 
- (modified) libcxx/include/__iterator/access.h (+4-4) 
- (modified) libcxx/include/__iterator/bounded_iter.h (+1-1) 
- (modified) libcxx/include/__iterator/move_iterator.h (+2-2) 
- (modified) libcxx/include/__iterator/reverse_iterator.h (+1-1) 
- (modified) libcxx/include/__iterator/wrap_iter.h (+1-1) 
- (modified) libcxx/include/__mdspan/extents.h (+4-4) 
- (modified) libcxx/include/__mdspan/mdspan.h (+1-1) 
- (modified) libcxx/include/__memory/unique_ptr.h (+2-2) 
- (modified) libcxx/include/__node_handle (+2-2) 
- (modified) libcxx/include/__ranges/chunk_by_view.h (+1-1) 
- (modified) libcxx/include/__ranges/empty_view.h (+2-2) 
- (modified) libcxx/include/__ranges/filter_view.h (+1-1) 
- (modified) libcxx/include/__ranges/iota_view.h (+1-1) 
- (modified) libcxx/include/__ranges/repeat_view.h (+3-3) 
- (modified) libcxx/include/__ranges/single_view.h (+4-4) 
- (modified) libcxx/include/__ranges/split_view.h (+1-1) 
- (modified) libcxx/include/__split_buffer (+8-8) 
- (modified) libcxx/include/__string/char_traits.h (+6-6) 
- (modified) libcxx/include/__thread/thread.h (+1-1) 
- (modified) libcxx/include/__tree (+14-14) 
- (modified) libcxx/include/any (+4-4) 
- (modified) libcxx/include/array (+36-36) 
- (modified) libcxx/include/bitset (+3-3) 
- (modified) libcxx/include/chrono (+6-6) 
- (modified) libcxx/include/deque (+49-49) 
- (modified) libcxx/include/experimental/__simd/simd.h (+1-1) 
- (modified) libcxx/include/experimental/__simd/simd_mask.h (+1-1) 
- (modified) libcxx/include/experimental/memory (+1-1) 
- (modified) libcxx/include/ext/hash_map (+40-40) 
- (modified) libcxx/include/ext/hash_set (+38-38) 
- (modified) libcxx/include/filesystem (+6-6) 
- (modified) libcxx/include/forward_list (+42-42) 
- (modified) libcxx/include/initializer_list (+8-8) 
- (modified) libcxx/include/iterator (+1-1) 
- (modified) libcxx/include/list (+46-46) 
- (modified) libcxx/include/map (+150-150) 
- (modified) libcxx/include/mdspan (+1-1) 
- (modified) libcxx/include/memory (+3-3) 
- (modified) libcxx/include/optional (+4-4) 
- (modified) libcxx/include/queue (+9-9) 
- (modified) libcxx/include/regex (+10-10) 
- (modified) libcxx/include/set (+126-126) 
- (modified) libcxx/include/span (+18-18) 
- (modified) libcxx/include/stack (+1-1) 
- (modified) libcxx/include/string (+57-57) 
- (modified) libcxx/include/string_view (+16-16) 
- (modified) libcxx/include/unordered_map (+138-138) 
- (modified) libcxx/include/unordered_set (+120-120) 
- (modified) libcxx/include/valarray (+16-16) 
- (modified) libcxx/include/variant (+9-9) 
- (modified) libcxx/include/vector (+85-85) 


``````````diff
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]

``````````

</details>


https://github.com/llvm/llvm-project/pull/112751


More information about the libcxx-commits mailing list