[clang] [LifetimeSafety] Fix false negative for GSL Owner type with arrow operator (PR #184725)
Zhijie Wang via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 5 12:06:40 PST 2026
================
@@ -152,8 +152,19 @@ bool shouldTrackImplicitObjectArg(const CXXMethodDecl *Callee,
return false;
if (isPointerLikeType(Callee->getReturnType())) {
- if (!Callee->getIdentifier())
+ if (!Callee->getIdentifier()) {
+ // e.g., std::optional<T>::operator->() returns T*.
+ if (Callee->getParent()->hasAttr<OwnerAttr>() &&
+ Callee->getOverloadedOperator() == OverloadedOperatorKind::OO_Arrow) {
+ if (RunningUnderLifetimeSafety)
+ return true;
+ // For Sema analysis, don't track operator-> when the pointee is a GSL
+ // Pointer (e.g., optional<string_view>), as Sema can't distinguish the
+ // Pointer object's lifetime from the data it observes.
+ return !isGslPointerType(Callee->getReturnType()->getPointeeType());
----------------
aeft wrote:
That makes sense. Updated.
https://github.com/llvm/llvm-project/pull/184725
More information about the cfe-commits
mailing list