Bug 1967374 - Use MOZ_LIFETIME_CAPTURE_BY instead of MOZ_LIFETIME_BOUND where it makes sense r=nika

Differential Revision: https://phabricator.services.mozilla.com/D250312
This commit is contained in:
serge-sans-paille
2025-05-21 15:33:48 +00:00
committed by sguelton@mozilla.com
parent aa16607cef
commit ed1122ceea
2 changed files with 18 additions and 3 deletions

View File

@@ -501,6 +501,21 @@
# define MOZ_LIFETIME_BOUND /* nothing */
#endif
/**
* MOZ_LIFETIME_CAPTURE_BY(x) indicates that objects that are referred to
* by that parameter may also be referred to by x.
* See: https://clang.llvm.org/docs/AttributeReference.html#lifetime-capture-by
*/
#if defined(__clang__) && defined(__has_cpp_attribute)
# if __has_cpp_attribute(clang::lifetime_capture_by)
# define MOZ_LIFETIME_CAPTURE_BY(x) [[clang::lifetime_capture_by(x)]]
# else
# define MOZ_LIFETIME_CAPTURE_BY(x) /* nothing */
# endif
#else
# define MOZ_LIFETIME_CAPTURE_BY(x) /* nothing */
#endif
#ifdef __cplusplus
/**

View File

@@ -110,12 +110,12 @@ class MOZ_GSL_POINTER nsTDependentString : public nsTString<T> {
*/
using nsTString<T>::Rebind;
void Rebind(const char_type* aData MOZ_LIFETIME_BOUND) {
void Rebind(const char_type* aData MOZ_LIFETIME_CAPTURE_BY(this)) {
Rebind(aData, char_traits::length(aData));
}
void Rebind(const char_type* aStart MOZ_LIFETIME_BOUND,
const char_type* aEnd MOZ_LIFETIME_BOUND);
void Rebind(const char_type* aStart MOZ_LIFETIME_CAPTURE_BY(this),
const char_type* aEnd MOZ_LIFETIME_CAPTURE_BY(this));
void Rebind(const string_type&, index_type aStartPos);
private: