llvm-project
8b6f3dcd - [LifetimeSafety] Suppress dangling field warnings for RAII resetters in permissive mode

Commit
10 days ago
[LifetimeSafety] Suppress dangling field warnings for RAII resetters in permissive mode (#214212) In `-Wlifetime-safety-permissive` mode, suppress dangling field warnings (`-Wlifetime-safety-dangling-field`) when `this` or the escaping field declaration is captured by a lambda within the function. This accounts for common RAII field resetters that clean up dangling pointers on scope exit. ### Motivating Example Dangling field analysis can report false positives when an RAII field resetter (such as `absl::MakeCleanup` or `absl::Cleanup`) captures `this` or the field to reset the pointer before function exit: ```cpp struct TimeServerInstance { Handler* handler_; void init() { Handler local_handler; handler_ = &local_handler; // False positive: intra-procedural analysis does not evaluate RAII // cleanup lambdas that reset dangling fields on scope exit. absl::Cleanup cleanup = [this] { handler_ = nullptr; }; } };
Author
Parents
Loading