[clang] [Sema] Fix lifetime extension for temporaries in range-based for loops in C++23 (PR #145164)

Yanzuo Liu via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 22 04:44:00 PDT 2025


================
@@ -57,6 +57,31 @@ enum LifetimeKind {
 };
 using LifetimeResult =
     llvm::PointerIntPair<const InitializedEntity *, 3, LifetimeKind>;
+
+/// Returns true if the given entity is part of a range-based for loop and
+/// should trigger lifetime extension under C++23 rules.
+///
+/// This handles both explicit range loop variables and internal compiler-
+/// generated variables like `__range1`.
+static bool
+isRangeBasedForLoopVariable(const Sema &SemaRef,
----------------
zwuis wrote:

This parameter type can be `const LangOptions &`.

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


More information about the cfe-commits mailing list