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

Marco Vitale via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 5 09:45:42 PDT 2025


mrcvtl wrote:

> I think we should revert to the previous approach, what do you think?
> 
> ```c++
>       if (IsGslPtrValueFromGslTempOwner && DiagLoc.isValid()) {
>         if (const auto *VD =
>                 dyn_cast_if_present<VarDecl>(ExtendingEntity->getDecl());
>             SemaRef.getLangOpts().CPlusPlus23 && VD &&
>             VD->isCXXForRangeImplicitVar())
>           return true;
>         SemaRef.Diag(DiagLoc, diag::warn_dangling_lifetime_pointer)
>             << DiagRange;
>         return false;
>       }
> ```

Thanks for debugging that!
I agree btw, didn't think about this side effect before.

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


More information about the cfe-commits mailing list