[clang] [LifetimeSafety] Trace assignment history for use-after-scope errors (PR #188467)
Yuan Suo via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 29 06:53:29 PDT 2026
suoyuan666 wrote:
> For chained member/arrow operations, we should highlight each step in the chain (with distinct ranges):
>
> ```c++
> const char* x = temporary().begin()->second.data();
> ```
>
> Would produce:
>
> ```c++
> warning: object whose reference is captured does not live long enough
> const char* x = temporary().begin()->second.data();
> ^~~~~~~~~~~
> note: destroyed here
> const char* x = temporary().begin()->second.data();
> ^
> note: expression aliases the storage of the temporary
> const char* x = temporary().begin()->second.data();
> ^~~~~~~~~~~~~~~~~~~
> note: member access aliases the storage of the temporary
> const char* x = temporary().begin()->second.data();
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~
> note: function call result aliases the storage of the temporary
> const char* x = temporary().begin()->second.data();
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> note: variable 'x' aliases the storage of the temporary
> const char* x = temporary().begin()->second.data();
> ^
> note: later used here
> (void)x;
> ^
> ```
Hi, I’ve moved the assignment backtracking logic from `LifetimeChecker` into a dedicated file and refactored the diagnostic handling to align with the format you suggested.
Regarding your example: `const char* x = temporary().begin()->second.data();`
I noticed the trace starts from `temporary().begin()` rather than `temporary()`. Are we intentionally skipping `CXXOperatorCallExpr` here, or is there a specific reason for this starting point?
https://github.com/llvm/llvm-project/pull/188467
More information about the cfe-commits
mailing list