File tree Expand file tree Collapse file tree 1 file changed +15
-42
lines changed
Expand file tree Collapse file tree 1 file changed +15
-42
lines changed Original file line number Diff line number Diff line change 1- // RUN: %check_clang_tidy %s readability-simplify-boolean-expr %t -- -- -std=c++17
1+ // RUN: clang-tidy %s -checks='-*,readability-simplify-boolean-expr' -- -std=c++17 | count 0
2+ struct RAII {};
3+ bool foo (bool Cond) {
4+ bool Result;
25
3- void test_init_stmt_true () {
4- void foo (int i);
5- if (int i = 0 ; true )
6- foo (i);
7- // CHECK-MESSAGES: :[[@LINE-2]]:18: warning: redundant boolean literal in if statement condition [readability-simplify-boolean-expr]
8- // CHECK-FIXES: { int i = 0; foo(i); };
9- }
10-
11- void test_init_stmt_false () {
12- void foo (int i);
13- if (int i = 0 ; false )
14- foo (i);
15- // CHECK-MESSAGES: :[[@LINE-2]]:18: warning: redundant boolean literal in if statement condition [readability-simplify-boolean-expr]
16- // CHECK-FIXES: { int i = 0; };
17- }
18-
19- void if_with_init_statement () {
20- bool x = true ;
21- if (bool y = x; y == true ) {
22- // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: redundant boolean literal supplied to boolean operator [readability-simplify-boolean-expr]
23- // CHECK-FIXES: if (bool y = x; y) {
24- }
25- }
26-
27- // This test verifies that we don't crash on C++17 init-statements with complex objects.
28- // We use function calls to prevent the "conditional assignment" check from triggering.
29- void test_cxx17_no_crash () {
30- struct RAII {};
31- bool Cond = true ;
32- void body ();
33- void else_body ();
6+ if (RAII Object; Cond)
7+ Result = true ;
8+ else
9+ Result = false ;
3410
35- if (RAII Object; Cond) {
36- body ();
37- } else {
38- else_body ();
39- }
11+ if (bool X = Cond; X)
12+ Result = true ;
13+ else
14+ Result = false ;
4015
41- if (bool X = Cond; X) {
42- body ();
43- } else {
44- else_body ();
45- }
16+ if (bool X = Cond; X)
17+ return true ;
18+ return false ;
4619}
You can’t perform that action at this time.
0 commit comments