[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 12 22:19:12 PST 2024
================
@@ -3223,6 +3225,49 @@ void Sema::CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl,
<< ParamName << (FDecl != nullptr) << FDecl;
}
+void Sema::checkLifetimeCaptureBy(FunctionDecl *FD, bool IsMemberFunction,
+ const Expr *ThisArg,
+ ArrayRef<const Expr *> Args) {
+ auto GetArgAt = [&](int Idx) {
+ if (IsMemberFunction && Idx == 0)
+ return const_cast<Expr *>(ThisArg);
+ return const_cast<Expr *>(Args[Idx - int(IsMemberFunction)]);
+ };
+ for (unsigned I = 0; I < FD->getNumParams(); ++I) {
+ auto *CapturedByAttr =
+ FD->getParamDecl(I)->getAttr<LifetimeCaptureByAttr>();
+ if (!CapturedByAttr)
+ continue;
+ for (int CapturingParamIdx : CapturedByAttr->params()) {
+ Expr *Capturing = GetArgAt(CapturingParamIdx);
+ Expr *Captured = GetArgAt(I + IsMemberFunction);
+ CapturingEntity CE{Capturing};
----------------
usx95 wrote:
Designated initializer is available in C++20 and in earlier C++ versions only as an extension. Although LLVM code is compatible with C++20, it would not be moved to default C++20 for quite some time.
https://github.com/llvm/llvm-project/pull/111499
More information about the cfe-commits
mailing list