[clang] [LifetimeSafety] Propagate inner origins through std::move and related casts (PR #199600)

via cfe-commits cfe-commits at lists.llvm.org
Wed May 27 08:21:31 PDT 2026


================
@@ -3376,3 +3373,38 @@ void deref_use_after_scope() {
 }
 
 } // namespace GH188832
+
+namespace GH191954 {
+  int* return_moved_pointer() {
+    int x;
+    int* f = &x; // expected-warning {{address of stack memory is returned later}}
+    int* a;
+    a = std::move(f);
+    return a; // expected-note {{returned here}}
+  }
+
+  int* return_moved_pointer2() {
+    int x;
+    int* f = &x;         // expected-warning {{address of stack memory is returned later}}
+    return std::move(f); // expected-note {{returned here}}
+  }
+
+  View return_moved_view() {
+    MyObj o;
+    View v(o); // expected-warning {{address of stack memory is returned later}}
+    View v2 = std::move(v);
+    return v2; // expected-note {{returned here}}
+  }
+
+  int* return_forwarded_pointer() {
+    int x;
+    int* f = &x;                  // expected-warning {{address of stack memory is returned later}}
+    return std::forward<int*>(f); // expected-note {{returned here}}
+  }
----------------
NeKon69 wrote:

We recently added a patch that  improves these warnings, can you please merge main into this branch and update them? #199432

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


More information about the cfe-commits mailing list