1 // RUN: %check_clang_tidy %s readability-misplaced-array-index %t
2
3 #define ABC "abc"
4
5 struct XY { int *X; int *Y; };
6
7 void dostuff(int);
8
unusualSyntax(int * P1,struct XY * P2)9 void unusualSyntax(int *P1, struct XY *P2) {
10 10[P1] = 0;
11 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: confusing array subscript expression, usually the index is inside the []
12 // CHECK-FIXES: P1[10] = 0;
13
14 10[P2->X] = 0;
15 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: confusing array subscript expression
16 // CHECK-FIXES: P2->X[10] = 0;
17
18 dostuff(1["abc"]);
19 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: confusing array subscript expression
20 // CHECK-FIXES: dostuff("abc"[1]);
21
22 dostuff(1[ABC]);
23 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: confusing array subscript expression
24 // CHECK-FIXES: dostuff(ABC[1]);
25
26 dostuff(0[0 + ABC]);
27 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: confusing array subscript expression
28 // CHECK-FIXES: dostuff(0[0 + ABC]);
29 // No fixit. Probably the code should be ABC[0]
30 }
31
normalSyntax(int * X)32 void normalSyntax(int *X) {
33 X[10] = 0;
34 }
35