[clang] [Clang] Extend lifetime of temporaries in mem-default-init for P2718R0 (PR #86960)

via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 9 07:00:42 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:

In `InitListChecker::FillInEmptyInitForField`, we will create a `CXXDefaultInitExpr` and fill in empty field `const A a& = A{};` for `for (auto &&x : B{}) {}` . Also there will have a `ExprWithCleanup` in `CXXDefaultInitExpr`. 
This is what I know about the difference in AST between the two cases, when I change the ExtendingDecl of `MaterializedTemporaryExpr`, it does not generate correct cleanups in CodeGen.

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


More information about the cfe-commits mailing list