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); 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;