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

via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 10 09:01: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:

I've another separate PR https://github.com/llvm/llvm-project/pull/87933 that support lifetime extension of temporary created by aggregate initialization using a default member initializer. In this case the temporary `A{}` created by aggregate initialization(I've misunderstand here before), I think since DR1815, it's well-formed.

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


More information about the cfe-commits mailing list