Index: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp @@ -22,9 +22,11 @@ // Flag all operators +, -, +=, -=, ++, -- that result in a pointer Finder->addMatcher( - binaryOperator(anyOf(hasOperatorName("+"), hasOperatorName("-"), - hasOperatorName("+="), hasOperatorName("-=")), - hasType(pointerType())) + binaryOperator( + anyOf(hasOperatorName("+"), hasOperatorName("-"), + hasOperatorName("+="), hasOperatorName("-=")), + hasType(pointerType()), + unless(hasLHS(ignoringImpCasts(declRefExpr(to(isImplicit())))))) .bind("expr"), this); @@ -36,8 +38,10 @@ // Array subscript on a pointer (not an array) is also pointer arithmetic Finder->addMatcher( - arraySubscriptExpr(hasBase(ignoringImpCasts(anyOf(hasType(pointerType()), - hasType(decayedType(hasDecayedType(pointerType()))))))) + arraySubscriptExpr( + hasBase(ignoringImpCasts( + anyOf(hasType(pointerType()), + hasType(decayedType(hasDecayedType(pointerType()))))))) .bind("expr"), this); } Index: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp +++ clang-tools-extra/trunk/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 }