1 // RUN: %check_clang_tidy %s readability-misleading-indentation %t 2 3 void foo1(); 4 void foo2(); 5 6 #define BLOCK \ 7 if (cond1) \ 8 foo1(); \ 9 foo2(); 10 main()11int main() 12 { 13 bool cond1 = true; 14 bool cond2 = true; 15 16 if (cond1) 17 if (cond2) 18 foo1(); 19 else 20 foo2(); 21 // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: different indentation for 'if' and corresponding 'else' [readability-misleading-indentation] 22 23 if (cond1) { 24 if (cond2) 25 foo1(); 26 } 27 else 28 foo2(); 29 30 if (cond1) 31 if (cond2) 32 foo1(); 33 else 34 foo2(); 35 36 if (cond2) 37 foo1(); 38 foo2(); 39 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: misleading indentation: statement is indented too deeply [readability-misleading-indentation] 40 // CHECK-MESSAGES: :[[@LINE-4]]:3: note: did you mean this line to be inside this 'if' 41 foo2(); // No redundant warning. 42 43 if (cond1) 44 { 45 foo1(); 46 } 47 foo2(); 48 49 if (cond1) 50 foo1(); 51 foo2(); 52 53 if (cond2) 54 if (cond1) foo1(); else foo2(); 55 56 if (cond1) { 57 } else { 58 } 59 60 if (cond1) { 61 } 62 else { 63 } 64 65 if (cond1) 66 { 67 } 68 else 69 { 70 } 71 72 if (cond1) 73 { 74 } 75 else 76 { 77 } 78 79 if(cond1) { 80 } 81 else if (cond2) { 82 } 83 else { 84 } 85 86 if(cond1) { 87 } 88 else if (cond2) { 89 } 90 else { 91 } 92 // CHECK-MESSAGES: :[[@LINE-2]]:8: warning: different indentation for 'if' and corresponding 'else' [readability-misleading-indentation] 93 94 if (cond1) { 95 if (cond1) { 96 } 97 else if (cond2) { 98 } 99 else { 100 } 101 if (cond1) { 102 } else if (cond2) { 103 } else if (!cond2) { 104 } else { 105 } 106 } 107 else if (cond2) { 108 } 109 110 BLOCK 111 } 112