[clang] Reapply "[clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #115823)
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 13 00:42:05 PST 2024
================
@@ -1889,6 +1889,43 @@ 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 AdditionalMembers = [{
+private:
+ MutableArrayRef<IdentifierInfo*> ArgIdents;
+ MutableArrayRef<SourceLocation> ArgLocs;
+
+public:
+ static constexpr int THIS = 0;
+ static constexpr int INVALID = -1;
+ static constexpr int UNKNOWN = -2;
+ static constexpr int GLOBAL = -3;
+
+ void CreateArgs(ASTContext &Ctx) {
+ ArgIdents =
+ MutableArrayRef<IdentifierInfo *>(new (Ctx) IdentifierInfo *[params_Size], params_Size);
+ ArgLocs =
+ MutableArrayRef<SourceLocation>(new (Ctx) SourceLocation[params_Size], params_Size);
+ }
+ auto getArgIdents() const {
----------------
hokein wrote:
Returning a `MutableArrayRef` and allowing mutations in the caller seems to break the encapsulation from a getter.
I’d prefer using an `ArrayRef` and adding a setter like `setArgIdents(ArrayRef<IdentifierInfo*> Args)`. While this means we’d allocate the array in the caller, I think it is fine.
https://github.com/llvm/llvm-project/pull/115823
More information about the cfe-commits
mailing list