[clang] [LifetimeSafety] Model scope-exit destructor and cleanup callback as a use (PR #204650)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 2 00:37:53 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}}
+}
----------------
usx95 wrote:
I might be confused with these tests. How is the callable `c` relevant for this test as it is not binding itself to the string or view ?
https://github.com/llvm/llvm-project/pull/204650
More information about the cfe-commits
mailing list