[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)
Gábor Horváth via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 13 03:54:37 PST 2024
================
@@ -793,3 +793,108 @@ void test13() {
}
} // namespace GH100526
+
+namespace lifetime_capture_by {
+struct S {
+ const int *x;
+ void captureInt(const int&x [[clang::lifetime_capture_by(this)]]) { this->x = &x; }
+ void captureSV(std::string_view sv [[clang::lifetime_capture_by(this)]]);
+};
+///////////////////////////
+// Detect dangling cases.
+///////////////////////////
+void captureInt(const int&x [[clang::lifetime_capture_by(s)]], S&s);
+void captureRValInt(int&&x [[clang::lifetime_capture_by(s)]], S&s);
+void noCaptureInt(int x [[clang::lifetime_capture_by(s)]], S&s);
----------------
Xazax-hun wrote:
Should we diagnose this as a misuse of the attribute?
https://github.com/llvm/llvm-project/pull/115921
More information about the cfe-commits
mailing list