[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
Wed Apr 10 08:52:31 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:

It makes sense that the extra ExprWithCleanups would force the destructor to run early, since that's supposed to be the marker for a full-expression.

Do we actually need to handle this case?  Looking at the current standard, it says "A temporary expression bound to a reference member from a default member initializer is ill-formed", which would seem to imply we should reject any case that would require this sort of lifetime extension.

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


More information about the cfe-commits mailing list