[clang] [Clang] Extend lifetime of temporaries in mem-default-init for P2718R0 (PR #86960)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 7 07:22:35 PDT 2024
================
@@ -1230,11 +1230,26 @@ CodeGenFunction::EmitCXXForRangeStmt(const CXXForRangeStmt &S,
JumpDest LoopExit = getJumpDestInCurrentScope("for.end");
LexicalScope ForScope(*this, S.getSourceRange());
+ const DeclStmt *RangeDS = cast<DeclStmt>(S.getRangeStmt());
+ const VarDecl *RangeVar = cast<VarDecl>(RangeDS->getSingleDecl());
+ if (getLangOpts().CPlusPlus23)
----------------
yronglin wrote:
Thanks for your review! [P2718R0](https://wg21.link/P2718R0) introduce lifetime extensions in for-range loops. Basic support for P2718R0 has been implemented in https://github.com/llvm/llvm-project/pull/76361 and everything works fine. When I works on this PR, I found that the lifetime of temporaries in`CXXDefaultInitExpr` was not extended, even if `MaterializedTemporaryExpr` sets ExtendingDecl and bound to `__range` variable. So I thought about my current approach and I'm not sure if this is the correct approach. Can you provide a direction for improvement? Should we modify the AST instead of handling it in CodeGen?
https://github.com/llvm/llvm-project/pull/86960
More information about the cfe-commits
mailing list