[PATCH] D14582: [clang-tidy] cppcoreguidelines-pro-bounds-pointer-arithmetic: ignore generated pointer arithmetic

Matthias Gehre via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 17 15:44:46 PST 2015


mgehre updated this revision to Diff 40448.
mgehre added a comment.

Simplified with Alex suggestion. Thanks!


http://reviews.llvm.org/D14582

Files:
  clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
  test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp

Index: test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
===================================================================
--- test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
+++ test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
@@ -84,4 +84,6 @@
   i = j - 1;
 
   auto diff = p - q; // OK, result is arithmetic
+
+  for(int ii : a) ; // OK, pointer arithmetic generated by compiler
 }
Index: clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
===================================================================
--- clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
@@ -24,7 +24,8 @@
   Finder->addMatcher(
       binaryOperator(anyOf(hasOperatorName("+"), hasOperatorName("-"),
                            hasOperatorName("+="), hasOperatorName("-=")),
-                     hasType(pointerType()))
+                     hasType(pointerType()),
+                     unless(hasLHS(ignoringImpCasts(declRefExpr(to(isImplicit()))))))
           .bind("expr"),
       this);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14582.40448.patch
Type: text/x-patch
Size: 1132 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151117/72b98dca/attachment.bin>


More information about the cfe-commits mailing list