[clang] [-Wunsafe-buffer-usage] Add unique_ptr <T[]> accesses (PR #156773)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 18 14:04:01 PDT 2025
================
@@ -1374,13 +1376,21 @@ class UniquePtrArrayAccessGadget : public WarningGadget {
if (!Method)
return false;
- if (Method->getNameAsString() != "operator[]")
+ if (Method->getOverloadedOperator() != OO_Subscript)
return false;
const CXXRecordDecl *RecordDecl = Method->getParent();
if (!isUniquePtrArray(RecordDecl))
return false;
+ const Expr *IndexExpr = OpCall->getArg(1);
+ llvm::APSInt IndexValue;
+
+ // Allow [0]
+ if (IndexExpr->EvaluateAsInt(IndexValue, Ctx) && IndexValue.isZero()) {
----------------
shreya-jain wrote:
Done, thanks
https://github.com/llvm/llvm-project/pull/156773
More information about the cfe-commits
mailing list