[clang] [LifetimeSafety] Model scope-exit destructor and cleanup callback as a use (PR #204650)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 2 01:53:35 PST 2026


================
@@ -1009,3 +1010,59 @@ struct S {
   }            // expected-note {{later used here}}
 };
 } // namespace CapturedByThis
+
+// Implicit uses at scope exit (destructors, cleanup callbacks) have no use
+// expression.
+namespace implicit_use_join {
+void view_and_callable() {
+  std::string text = "long enough heap-allocated backing string value here!";
+  std::string_view tok = text;
+  std::function<void()> c = [] {};
+  (void)c;
+  (void)tok.size();
+}
+
+void view_and_callable_mutation() {
+  std::string text = "long enough heap-allocated backing string value here!";
+  std::string_view tok = text; // expected-warning {{local variable 'text' is later invalidated}}
+  std::function<void()> c = [] {};
+  (void)c;
+  text.push_back('x'); // expected-note {{local variable 'text' is invalidated here}}
+  (void)tok.size();    // expected-note {{later used here}}
+}
----------------
Xazax-hun wrote:

Oh, indeed. These tests are gone, they didn't do anything. 

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


More information about the cfe-commits mailing list