[clang] [Sema] Fix lifetime extension for temporaries in range-based for loops in C++23 (PR #145164)

via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 22 05:10:28 PDT 2025


yronglin wrote:

> A couple of quick notes:
> 
> * This is my first LLVM PR, so if there are any issues with code style or conventions, please let me know!
> * I'm not entirely satisfied with the `VD->getName().starts_with("__range")` check, but it was the most reliable approach I found. Walking up the AST from the node didn’t seem feasible (likely due to optimizations?) and I noticed that pattern here: https://github.com/llvm/llvm-project/blob/075cb691a5e810f7114369c67b475dfd9127d4af/clang/lib/Sema/SemaStmt.cpp#L2481-L2485

Thanks for you fix!
Maybe we can use `isInLifetimeExtendingContext()` instead of check the `__range` variable name. We usually  get into an `LifetimeExtendingContex` in Sema. FYI, the initial PR is https://github.com/llvm/llvm-project/pull/76361.

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


More information about the cfe-commits mailing list