[clang] [Clang] Extend lifetime of temporaries in mem-default-init for P2718R0 (PR #86960)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 26 07:35:33 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:
> The AST in the `B{A()}` case looks like the following. If your patch changes the AST for `B{}` to look the same, it should be fine, I think? From your description, I'm not exactly sure what's different about what CXXDefaultInitExpr rewriting generates.
>
> ```
> | `-VarDecl 0xc4927c0 <col:113, col:118> col:113 implicit used __range1 'B &&' cinit
> | `-ExprWithCleanups 0xc492aa8 <col:113, col:118> 'B' xvalue
> | `-MaterializeTemporaryExpr 0xc492a00 <col:113, col:118> 'B' xvalue extended by Var 0xc4927c0 '__range1' 'B &&'
> | `-CXXFunctionalCastExpr 0xc492678 <col:113, col:118> 'B' functional cast to B <NoOp>
> | `-InitListExpr 0xc492508 <col:114, col:118> 'B'
> | `-MaterializeTemporaryExpr 0xc492568 <col:115, col:117> 'const A' lvalue extended by Var 0xc4927c0 '__range1' 'B &&'
> | `-ImplicitCastExpr 0xc492550 <col:115, col:117> 'const A' <NoOp>
> | `-CXXBindTemporaryExpr 0xc4718c8 <col:115, col:117> 'A' (CXXTemporary 0xc4718c8)
> | `-CXXTemporaryObjectExpr 0xc471890 <col:115, col:117> 'A' 'void ()'
> ```
I have addressed this suggestion, seems it's works fine now, and avoid the changes in CodeGen.
https://github.com/llvm/llvm-project/pull/86960
More information about the cfe-commits
mailing list