diff --git a/mfbt/Attributes.h b/mfbt/Attributes.h index a948a97d9646..2f50601b0306 100644 --- a/mfbt/Attributes.h +++ b/mfbt/Attributes.h @@ -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 /** diff --git a/xpcom/string/nsTDependentString.h b/xpcom/string/nsTDependentString.h index 0c0efd432a05..acb4ecf41686 100644 --- a/xpcom/string/nsTDependentString.h +++ b/xpcom/string/nsTDependentString.h @@ -110,12 +110,12 @@ class MOZ_GSL_POINTER nsTDependentString : public nsTString { */ using nsTString::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: