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

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 8 11:23:29 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)
----------------
efriedma-quic wrote:

`for (auto &&x : B{A()}) {}` currently works correctly, as far as I know (where B is a class with a member of type `const A&`).  And if I'm understanding correctly, `for (auto &&x : B{}) {}` is supposed to be semantically equivalent.  If the AST is significantly different, you should be addressing that in Sema, I think.

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


More information about the cfe-commits mailing list