[clang] [-Wunsafe-buffer-usage] Add unique_ptr <T[]> accesses (PR #156773)

Florian Mayer via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 18 14:47:58 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()) {
----------------
fmayer wrote:

it seems you forgot to upload

https://github.com/llvm/llvm-project/pull/156773


More information about the cfe-commits mailing list