[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)
Gábor Horváth via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 11 06:59:08 PST 2024
================
@@ -3967,6 +3967,69 @@ Attribute ``trivial_abi`` has no effect in the following cases:
}];
}
+
+def LifetimeCaptureByDocs : Documentation {
+ let Category = DocCatFunction;
+ let Content = [{
+ The ``lifetime_capture_by(X)`` attribute on a function parameter or implicit object
+parameter indicates that references to arguments passed to such parameters may be
+captured by the capturing entity ``X``.
+
+The capturing entity ``X`` can be one of the following:
+- Another (named) function parameter.
+
+ .. code-block:: c++
+
+ void addToSet(std::string_view a [[clang::lifetime_capture_by(s)]], std::set<std::string_view>& s) {
+ s.insert(a);
+ }
+
+- ``this`` (in case of member functions).
+
+ .. code-block:: c++
+
+ class S {
+ void addToSet(std::string_view a [[clang::lifetime_capture_by(this)]]) {
+ s.insert(a);
+ }
+ std::set<std::string_view> s;
+ };
+
+- 'global', 'unknown' (without quotes).
+
+ .. code-block:: c++
+
+ std::set<std::string_view> s;
+ void addToSet(std::string_view a [[clang::lifetime_capture_by(global)]]) {
----------------
Xazax-hun wrote:
I think this is not a blocker for this patch. We could add a diagnostic as @hokein suggested, and we can change the behavior in a follow-up patch later.
https://github.com/llvm/llvm-project/pull/111499
More information about the cfe-commits
mailing list