@@ -1304,13 +1304,6 @@ checkExprLifetimeImpl(Sema &SemaRef, const InitializedEntity *InitEntity,
13041304 if (LK == LK_FullExpression)
13051305 return ;
13061306
1307- if (LK == LK_Extended && SemaRef.getLangOpts ().CPlusPlus23 ) {
1308- if (const auto *VD = dyn_cast_if_present<VarDecl>(InitEntity->getDecl ())) {
1309- if (VD->isCXXForRangeImplicitVar ())
1310- return ;
1311- }
1312- }
1313-
13141307 // FIXME: consider moving the TemporaryVisitor and visitLocalsRetained*
13151308 // functions to a dedicated class.
13161309 auto TemporaryVisitor = [&](const IndirectLocalPath &Path, Local L,
@@ -1347,12 +1340,6 @@ checkExprLifetimeImpl(Sema &SemaRef, const InitializedEntity *InitEntity,
13471340 return false ;
13481341 }
13491342
1350- if (IsGslPtrValueFromGslTempOwner && DiagLoc.isValid ()) {
1351- SemaRef.Diag (DiagLoc, diag::warn_dangling_lifetime_pointer)
1352- << DiagRange;
1353- return false ;
1354- }
1355-
13561343 switch (shouldLifetimeExtendThroughPath (Path)) {
13571344 case PathLifetimeKind::Extend:
13581345 // Update the storage duration of the materialized temporary.
@@ -1363,6 +1350,20 @@ checkExprLifetimeImpl(Sema &SemaRef, const InitializedEntity *InitEntity,
13631350 return true ;
13641351
13651352 case PathLifetimeKind::NoExtend:
1353+ if (SemaRef.getLangOpts ().CPlusPlus23 && InitEntity) {
1354+ if (const VarDecl *VD =
1355+ dyn_cast_if_present<VarDecl>(InitEntity->getDecl ());
1356+ VD && VD->isCXXForRangeImplicitVar ()) {
1357+ return false ;
1358+ }
1359+ }
1360+
1361+ if (IsGslPtrValueFromGslTempOwner && DiagLoc.isValid ()) {
1362+ SemaRef.Diag (DiagLoc, diag::warn_dangling_lifetime_pointer)
1363+ << DiagRange;
1364+ return false ;
1365+ }
1366+
13661367 // If the path goes through the initialization of a variable or field,
13671368 // it can't possibly reach a temporary created in this full-expression.
13681369 // We will have already diagnosed any problems with the initializer.
0 commit comments