[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 04:19:44 PST 2024


================
@@ -1889,6 +1889,40 @@ def LifetimeBound : DeclOrTypeAttr {
   let SimpleHandler = 1;
 }
 
+def LifetimeCaptureBy : DeclOrTypeAttr {
+  let Spellings = [Clang<"lifetime_capture_by", 0>];
+  let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>;
+  let Args = [VariadicParamOrParamIdxArgument<"Params">];
+  let Documentation = [LifetimeCaptureByDocs];
+  let LangOpts = [CPlusPlus];
+  let AdditionalMembers = [{
+private:
+  SmallVector<IdentifierInfo*, 1> ArgIdents;
+  SmallVector<SourceLocation, 1> ArgLocs;
+
+public:
+  static constexpr int THIS = 0;
+  static constexpr int INVALID = -1;
+  static constexpr int UNKNOWN = -2;
+  static constexpr int GLOBAL = -3;
+
+  void setArgs(SmallVector<IdentifierInfo*, 1>&& Idents,
----------------
Xazax-hun wrote:

Nit: would something like `SmallVectorImpl<IdentifierInfo>&& Idents` work here? If it did, it would make use sites more flexible, not forcing an inline buffer size on the callee. 

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


More information about the cfe-commits mailing list