[PATCH] D14582: [clang-tidy] cppcoreguidelines-pro-bounds-pointer-arithmetic: ignore generated pointer arithmetic
Matthias Gehre via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 26 14:35:08 PST 2015
This revision was automatically updated to reflect the committed changes.
Closed by commit rL254182: [clang-tidy] cppcoreguidelines-pro-bounds-pointer-arithmetic: ignore… (authored by mgehre).
Changed prior to commit:
http://reviews.llvm.org/D14582?vs=40448&id=41272#toc
Repository:
rL LLVM
http://reviews.llvm.org/D14582
Files:
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
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
}
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);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14582.41272.patch
Type: text/x-patch
Size: 2020 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151126/fe45cdde/attachment.bin>
More information about the cfe-commits
mailing list