diff --git a/mfbt/Attributes.h b/mfbt/Attributes.h index ff5b7f74951b..4c4b1d2baeb8 100644 --- a/mfbt/Attributes.h +++ b/mfbt/Attributes.h @@ -486,6 +486,24 @@ # define MOZ_LIFETIME_CAPTURE_BY(x) /* nothing */ #endif +/** + * MOZ_LIFETIME_CAPTURE_BY_THIS is the equivalent of + * MOZ_LIFETIME_CAPTURE_BY(this). It needs to be spelled differently because + * clang 23 deprecated passing `this` to lifetime_capture_by in favor of the + * dedicated lifetime_capture_by_this attribute. + */ +#if defined(__clang__) && defined(__has_cpp_attribute) +# if __has_cpp_attribute(clang::lifetime_capture_by_this) +# define MOZ_LIFETIME_CAPTURE_BY_THIS [[clang::lifetime_capture_by_this]] +# elif __has_cpp_attribute(clang::lifetime_capture_by) +# define MOZ_LIFETIME_CAPTURE_BY_THIS [[clang::lifetime_capture_by(this)]] +# else +# define MOZ_LIFETIME_CAPTURE_BY_THIS /* nothing */ +# endif +#else +# define MOZ_LIFETIME_CAPTURE_BY_THIS /* nothing */ +#endif + /** * MOZ_REINITIALIZES tells static analyser that a call to the associated * method leave it in an initialized state, typically after a std::move. diff --git a/mfbt/api.yml b/mfbt/api.yml index ae4268a04f2c..0cf113412257 100644 --- a/mfbt/api.yml +++ b/mfbt/api.yml @@ -101,6 +101,7 @@ Attributes.h: - MOZ_GSL_POINTER - MOZ_LIFETIME_BOUND - MOZ_LIFETIME_CAPTURE_BY + - MOZ_LIFETIME_CAPTURE_BY_THIS - MOZ_STANDALONE_DEBUG - MOZ_NULL_AFTER_MOVE - MOZ_PUSH_DISABLE_NONTRIVIAL_UNION_WARNINGS diff --git a/xpcom/string/nsTDependentString.h b/xpcom/string/nsTDependentString.h index a4e99bd4f6cb..d0191c4efc2f 100644 --- a/xpcom/string/nsTDependentString.h +++ b/xpcom/string/nsTDependentString.h @@ -103,12 +103,12 @@ class MOZ_GSL_POINTER nsTDependentString : public nsTString { */ using nsTString::Rebind; - void Rebind(const char_type* aData MOZ_LIFETIME_CAPTURE_BY(this)) { + 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_CAPTURE_BY(this), - const char_type* aEnd MOZ_LIFETIME_CAPTURE_BY(this)); + 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); protected: