================
@@ -3284,3 +3284,76 @@ void assign_non_capturing_to_function_ref(function_ref
&r) {
}
} // namespace GH126600
+
+//===----------------------------------------------------------------------===//
+// lifetime-capture-by
+//===----------------------------------------------------------------------===//
+
+void setCaptureBy(View& in, View out [[clang::lifetime_capture_by(in)]]);
+
+void use_after_free_capture_by() {
+ View res;
+ {
+ MyObj a;
+ setCaptureBy(res, a); // expected-warning {{object whose reference is
captured does not live long enough}}
+ } // expected-note {{destroyed here}}
+ (void)res; // expected-note {{later used here}}
+}
+
+View use_after_return_capture_by() {
+ MyObj a;
+ View res;
+ setCaptureBy(res, a); // expected-warning {{address of stack memory is
returned later}}
+ return res; // expected-note {{returned here}}
+
+}
+
+void transitive_capture() {
+ View v1, v2;
+ {
+ MyObj local;
+ setCaptureBy(v1, local); // expected-warning {{object whose reference is
captured does not live long enough}}
+ setCaptureBy(v2, v1);
+ } // expected-note {{destroyed here}}
+ (void)v2; // expected-note {{later used here}}
+}
+
+struct [[gsl::Pointer]] MyContainer {
----------------
usx95 wrote:
On a deeper thought, looks like that the change to
`LifetimeAnnotatedOriginTypeCollector` is not very small.
I am fine adding a FIXME for now for this ideally with github issue.
https://github.com/llvm/llvm-project/pull/196884
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits