summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp14
-rw-r--r--clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp2
2 files changed, 11 insertions, 5 deletions
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);
}
diff --git a/clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp b/clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
index c8fea8052e5..7cbc6ddf96a 100644
--- a/clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
+++ b/clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
@@ -84,4 +84,6 @@ void okay() {
i = j - 1;
auto diff = p - q; // OK, result is arithmetic
+
+ for(int ii : a) ; // OK, pointer arithmetic generated by compiler
}
OpenPOWER on IntegriCloud