1// RUN: %check_clang_tidy %s readability-simplify-boolean-expr %t -- -config="{CheckOptions: {readability-simplify-boolean-expr.ChainedConditionalAssignment: true}}" --
2
3void chained_conditional_compound_assignment(int i) {
4 bool b;
5 if (i < 0) {
6 b = true;
7 } else if (i < 10) {
8 b = false;
9 } else if (i > 20) {
10 b = true;
11 } else {
12 b = false;
13 }
14 // CHECK-MESSAGES: :[[@LINE-4]]:9: warning: redundant boolean literal in conditional assignment [readability-simplify-boolean-expr]
15 // CHECK-FIXES: {{^}} } else if (i < 10) {{{$}}
16 // CHECK-FIXES-NEXT: {{^}} b = false;{{$}}
17 // CHECK-FIXES-NEXT: {{^}} } else b = i > 20;{{$}}
18}
19
20void chained_conditional_assignment(int i) {
21 bool b;
22 if (i < 0)
23 b = true;
24 else if (i < 10)
25 b = false;
26 else if (i > 20)
27 b = true;
28 else
29 b = false;
30 // CHECK-MESSAGES: :[[@LINE-3]]:9: warning: {{.*}} in conditional assignment
31 // CHECK-FIXES: {{^}} else if (i < 10)
32 // CHECK-FIXES-NEXT: {{^}} b = false;
33 // CHECK-FIXES-NEXT: {{^}} else b = i > 20;
34}
35

source code of clang-tools-extra/test/clang-tidy/checkers/readability/simplify-boolean-expr-chained-conditional-assignment.cpp