1 // RUN: %check_clang_tidy -std=c++14-or-later %s cppcoreguidelines-pro-bounds-pointer-arithmetic %t
2 
3 // Fix PR36489 and detect auto-deduced value correctly.
4 char *getPtr();
getPtrAuto()5 auto getPtrAuto() { return getPtr(); }
6 decltype(getPtr()) getPtrDeclType();
getPtrDeclTypeAuto()7 decltype(auto) getPtrDeclTypeAuto() { return getPtr(); }
8 auto getPtrWithTrailingReturnType() -> char *;
9 
auto_deduction_binary()10 void auto_deduction_binary() {
11   auto p1 = getPtr() + 1;
12   // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: do not use pointer arithmetic
13   auto p2 = getPtrAuto() + 1;
14   // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: do not use pointer arithmetic
15   auto p3 = getPtrWithTrailingReturnType() + 1;
16   // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: do not use pointer arithmetic
17   auto p4 = getPtr();
18   auto *p5 = getPtr();
19   p4 = p4 + 1;
20   // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not use pointer arithmetic
21   p5 = p5 + 1;
22   // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not use pointer arithmetic
23   auto p6 = getPtrDeclType() + 1;
24   // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: do not use pointer arithmetic
25   auto p7 = getPtrDeclTypeAuto() + 1;
26   // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: do not use pointer arithmetic
27   auto *p8 = getPtrDeclType() + 1;
28   // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: do not use pointer arithmetic
29   auto *p9 = getPtrDeclTypeAuto() + 1;
30   // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: do not use pointer arithmetic
31 }
32 
auto_deduction_subscript()33 void auto_deduction_subscript() {
34   char p1 = getPtr()[2];
35   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic
36   auto p2 = getPtr()[3];
37   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic
38 
39   char p3 = getPtrAuto()[4];
40   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic
41   auto p4 = getPtrAuto()[5];
42   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic
43 
44   char p5 = getPtrWithTrailingReturnType()[6];
45   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic
46   auto p6 = getPtrWithTrailingReturnType()[7];
47   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic
48 
49   auto p7 = getPtrDeclType()[8];
50   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic
51   auto p8 = getPtrDeclTypeAuto()[9];
52   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic
53 }
54