[clang] [LifetimeSafety] Add support for iterator arithmetic (PR #195442)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Mon May 4 00:58:31 PDT 2026
================
@@ -139,8 +140,10 @@ bool shouldTrackImplicitObjectArg(const CXXMethodDecl *Callee,
if (RunningUnderLifetimeSafety &&
isGslPointerType(Callee->getFunctionObjectParameterType()) &&
isReferenceOrPointerLikeType(Callee->getReturnType())) {
- if (Callee->getOverloadedOperator() == OverloadedOperatorKind::OO_Star ||
- Callee->getOverloadedOperator() == OverloadedOperatorKind::OO_Arrow)
+ auto Op = Callee->getOverloadedOperator();
+ llvm::SmallDenseSet<OverloadedOperatorKind> PropagatingOps = {
+ OO_Star, OO_Arrow, OO_PlusPlus, OO_MinusMinus, OO_Plus, OO_Minus};
+ if (PropagatingOps.contains(Op))
----------------
usx95 wrote:
Consider using a `switch` block for `enum` instead of a `set`.
```cpp
switch (Callee->getOverloadedOperator()) {
case OO_Star: case OO_Arrow: case OO_PlusPlus:
case OO_MinusMinus: case OO_Plus: case OO_Minus:
return true;
default:
break;
}
```
Consider adding a line documenting this part.
`// Propagate origins through GSL pointer arithmetic and dereference operators.
`
https://github.com/llvm/llvm-project/pull/195442
More information about the cfe-commits
mailing list