From 4241cedb68d61d85dd12b64d6792d0277f9ff4b2 Mon Sep 17 00:00:00 2001 From: Matthias Gehre Date: Thu, 26 Nov 2015 22:32:11 +0000 Subject: [clang-tidy] cppcoreguidelines-pro-bounds-pointer-arithmetic: ignore generated pointer arithmetic Summary: Inside a range-based for-loop over an array, the compiler generates pointer arithmetic (end = array + size). Don't flag this. Reviewers: alexfh, sbenza, bkramer, aaron.ballman Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D14582 llvm-svn: 254182 --- .../cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp') diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp index 15ea27a4462..9dcd7c4a370 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp @@ -22,9 +22,11 @@ void ProBoundsPointerArithmeticCheck::registerMatchers(MatchFinder *Finder) { // 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 @@ void ProBoundsPointerArithmeticCheck::registerMatchers(MatchFinder *Finder) { // 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); } -- cgit v1.2.3