Skip to content

Commit 5cd4938

Browse files
committed
simplify capture analysis
1 parent 37259f2 commit 5cd4938

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

clang/lib/Sema/CheckExprLifetime.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,13 +1452,8 @@ checkExprLifetimeImpl(Sema &SemaRef, const InitializedEntity *InitEntity,
14521452
}
14531453
case LK_LifetimeCapture: {
14541454
Path.push_back({IndirectLocalPathEntry::LifetimeCapture, Init});
1455-
if (isRecordWithAttr<PointerAttr>(Init->getType()))
1456-
HasReferenceBinding = false;
1457-
// Skip the top MTE if it is a temporary object of the pointer-like type
1458-
// itself.
1459-
if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(Init);
1460-
MTE && isPointerLikeType(Init->getType()))
1461-
Init = MTE->getSubExpr();
1455+
if (isPointerLikeType(Init->getType()))
1456+
Path.push_back({IndirectLocalPathEntry::GslPointerInit, Init});
14621457
break;
14631458
}
14641459
default:

clang/test/Sema/warn-lifetime-analysis-capture-by.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,9 @@ void use_with_optional_view() {
309309
vector_of_view.push_back(optional_of_view.value());
310310
vector_of_view.push_back(getOptionalS().value()); // expected-warning {{captured}}
311311

312-
// FIXME: Following 2 cases are false positives:
313-
vector_of_view.push_back(getOptionalSV().value()); // expected-warning {{captured}}
314-
vector_of_view.push_back(getOptionalMySV().value()); // expected-warning {{captured}}
315-
316-
// (maybe) FIXME: We may choose to diagnose the following case.
317-
// This happens because 'MyStringViewNotPointer' is not marked as a [[gsl::Pointer]] but is derived from one.
318-
vector_of_view.push_back(getOptionalMySVNotP().value()); // expected-warning {{captured}}
312+
vector_of_view.push_back(getOptionalSV().value());
313+
vector_of_view.push_back(getOptionalMySV().value());
314+
vector_of_view.push_back(getOptionalMySVNotP().value());
319315
}
320316
} // namespace conatiners_with_different
321317

0 commit comments

Comments
 (0)