[clang] [LifetimeSafety] Track STL algorithm functions that return lifetimebound iterators (PR #179227)
Gábor Horváth via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 2 06:56:46 PST 2026
================
@@ -174,13 +174,41 @@ bool shouldTrackImplicitObjectArg(const CXXMethodDecl *Callee,
}
bool shouldTrackFirstArgument(const FunctionDecl *FD) {
- if (!FD->getIdentifier() || FD->getNumParams() != 1)
+ if (!FD->getIdentifier() || FD->getNumParams() < 1)
return false;
+ if (!FD->isInStdNamespace())
+ return false;
+ // Track std:: algorithm functions that return an iterator whose lifetime is
+ // bound to the first argument.
+ if (FD->getNumParams() >= 2 && FD->isInStdNamespace() &&
+ isGslPointerType(FD->getReturnType())) {
+ if (llvm::StringSwitch<bool>(FD->getName())
+ .Cases(
+ {
+ "find",
----------------
Xazax-hun wrote:
How comprehensive do we want to be here?
There are the `ranges` variants.
And some more STL functions that modify the container like `rotate`, or `partition` also return iterators that are lifetime dependent.
That being said, I am also fine landing support for some of those in a follow-up.
https://github.com/llvm/llvm-project/pull/179227
More information about the cfe-commits
mailing list