[PATCH] D43745: Fix cppcoreguidelines-pro-bounds-pointer-arithmetic not working for functions with auto return specifier.
Alexandru Octavian Buțiu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 25 09:05:10 PST 2018
predator5047 created this revision.
predator5047 added reviewers: alexfh, alexfh_.
predator5047 added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, kbarton, nemanjai.
Fix bug #36489
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D43745
Files:
clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
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
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-pro-bounds-pointer-arithmetic %t
+// RUN: %check_clang_tidy %s cppcoreguidelines-pro-bounds-pointer-arithmetic %t -- -- -std=c++14
enum E {
ENUM_LITERAL = 1
@@ -9,7 +9,36 @@
int *p = 0;
int *q = 0;
+int* pointer() {
+ return nullptr;
+}
+
+auto pointerAuto() {
+ return (int*) nullptr;
+}
+
+auto pointerAutoTrailing() -> int* {
+ return (int*) nullptr;
+}
+
void fail() {
+ auto x = (int*) nullptr;
+ p = x + 1;
+ // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not use pointer arithmetic
+ p = pointer() + 1;
+ // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not use pointer arithmetic
+ p = pointerAuto() + 1;
+ // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not use pointer arithmetic
+ p = pointerAutoTrailing() + 1;
+ // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not use pointer arithmetic
+
+ p = 1 + pointer();
+ // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not use pointer arithmetic
+ p = 1 + pointerAuto();
+ // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not use pointer arithmetic
+ p = 1 + pointerAutoTrailing();
+ // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not use pointer arithmetic
+
q = p + 4;
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
p = q + i;
Index: clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
===================================================================
--- clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp
@@ -26,7 +26,7 @@
binaryOperator(
anyOf(hasOperatorName("+"), hasOperatorName("-"),
hasOperatorName("+="), hasOperatorName("-=")),
- hasType(pointerType()),
+ anyOf(hasType(pointerType()), hasType(autoType(hasDeducedType(pointerType())))),
unless(hasLHS(ignoringImpCasts(declRefExpr(to(isImplicit()))))))
.bind("expr"),
this);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43745.135831.patch
Type: text/x-patch
Size: 2436 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180225/7b197a41/attachment.bin>
More information about the cfe-commits
mailing list