Index: clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp =================================================================== --- clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp +++ clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp @@ -16,6 +16,18 @@ namespace clang { namespace tidy { +AST_MATCHER_P(CXXForRangeStmt, hasRangeBeginEndStmt, + ast_matchers::internal::Matcher, InnerMatcher) { + const DeclStmt *const Stmt = Node.getBeginEndStmt(); + return (Stmt != nullptr && InnerMatcher.matches(*Stmt, Finder, Builder)); +} + +AST_MATCHER(Stmt, isInsideOfRangeBeginEndStmt) { + return stmt(hasAncestor(cxxForRangeStmt( + hasRangeBeginEndStmt(hasDescendant(equalsNode(&Node)))))) + .matches(Node, Finder, Builder); +} + void ProBoundsPointerArithmeticCheck::registerMatchers(MatchFinder *Finder) { if (!getLangOpts().CPlusPlus) return; @@ -24,7 +36,8 @@ Finder->addMatcher( binaryOperator(anyOf(hasOperatorName("+"), hasOperatorName("-"), hasOperatorName("+="), hasOperatorName("-=")), - hasType(pointerType())) + hasType(pointerType()), + unless(isInsideOfRangeBeginEndStmt())) .bind("expr"), this); 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 }