brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1009 B · 43dd458 Raw
35 lines · cpp
1// RUN: %check_clang_tidy %s readability-misplaced-array-index %t2 3#define ABC  "abc"4 5struct XY { int *X; int *Y; };6 7void dostuff(int);8 9void 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 expression16  // CHECK-FIXES: P2->X[10] = 0;17 18  dostuff(1["abc"]);19  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: confusing array subscript expression20  // CHECK-FIXES:  dostuff("abc"[1]);21 22  dostuff(1[ABC]);23  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: confusing array subscript expression24  // CHECK-FIXES:  dostuff(ABC[1]);25 26  dostuff(0[0 + ABC]);27  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: confusing array subscript expression28  // CHECK-FIXES:  dostuff(0[0 + ABC]);29  // No fixit. Probably the code should be ABC[0]30}31 32void normalSyntax(int *X) {33  X[10] = 0;34}35