[clang-tidy][modernize-use-starts-ends-with] Fix operator rewriting false negative...
[llvm-project.git] / clang / test / Sema / logical-op-parentheses.c
blob9a11a3e5fac3c1e394f1d56a8ed07e241f7ea421
1 // RUN: %clang_cc1 -fsyntax-only -verify %s -DSILENCE
2 // RUN: %clang_cc1 -fsyntax-only -verify %s -Wlogical-op-parentheses
3 // RUN: %clang_cc1 -fsyntax-only -verify %s -Wparentheses
4 // RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s -Wlogical-op-parentheses 2>&1 | FileCheck %s
6 #ifdef SILENCE
7 // expected-no-diagnostics
8 #endif
10 void logical_op_parentheses(unsigned i) {
11 const unsigned t = 1;
12 (void)(i ||
13 i && i);
14 #ifndef SILENCE
15 // expected-warning@-2 {{'&&' within '||'}}
16 // expected-note@-3 {{place parentheses around the '&&' expression to silence this warning}}
17 #endif
18 // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:14-[[@LINE-5]]:14}:"("
19 // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:20-[[@LINE-6]]:20}:")"
21 (void)(t ||
22 t && t);
23 #ifndef SILENCE
24 // expected-warning@-2 {{'&&' within '||'}}
25 // expected-note@-3 {{place parentheses around the '&&' expression to silence this warning}}
26 #endif
27 // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:14-[[@LINE-5]]:14}:"("
28 // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:20-[[@LINE-6]]:20}:")"
30 (void)(t &&
31 t || t);
32 #ifndef SILENCE
33 // expected-warning@-3 {{'&&' within '||'}}
34 // expected-note@-4 {{place parentheses around the '&&' expression to silence this warning}}
35 #endif
36 // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:10-[[@LINE-6]]:10}:"("
37 // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:15-[[@LINE-6]]:15}:")"
39 (void)(i || i && "w00t");
40 (void)("w00t" && i || i);
41 (void)("w00t" && t || t);
42 (void)(t && t || 0);
43 #ifndef SILENCE
44 // expected-warning@-2 {{'&&' within '||'}}
45 // expected-note@-3 {{place parentheses around the '&&' expression to silence this warning}}
46 #endif
47 // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:10-[[@LINE-5]]:10}:"("
48 // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:16-[[@LINE-6]]:16}:")"
49 (void)(1 && t || t);
50 #ifndef SILENCE
51 // expected-warning@-2 {{'&&' within '||'}}
52 // expected-note@-3 {{place parentheses around the '&&' expression to silence this warning}}
53 #endif
54 // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:10-[[@LINE-5]]:10}:"("
55 // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:16-[[@LINE-6]]:16}:")"
56 (void)(0 || t && t);
57 #ifndef SILENCE
58 // expected-warning@-2 {{'&&' within '||'}}
59 // expected-note@-3 {{place parentheses around the '&&' expression to silence this warning}}
60 #endif
61 // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:15-[[@LINE-5]]:15}:"("
62 // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:21-[[@LINE-6]]:21}:")"
63 (void)(t || t && 1);
64 #ifndef SILENCE
65 // expected-warning@-2 {{'&&' within '||'}}
66 // expected-note@-3 {{place parentheses around the '&&' expression to silence this warning}}
67 #endif
68 // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:15-[[@LINE-5]]:15}:"("
69 // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:21-[[@LINE-6]]:21}:")"
71 (void)(i || i && "w00t" || i);
72 #ifndef SILENCE
73 // expected-warning@-2 {{'&&' within '||'}}
74 // expected-note@-3 {{place parentheses around the '&&' expression to silence this warning}}
75 #endif
76 // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:15-[[@LINE-5]]:15}:"("
77 // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:26-[[@LINE-6]]:26}:")"
79 (void)(i || "w00t" && i || i);
80 #ifndef SILENCE
81 // expected-warning@-2 {{'&&' within '||'}}
82 // expected-note@-3 {{place parentheses around the '&&' expression to silence this warning}}
83 #endif
84 // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:15-[[@LINE-5]]:15}:"("
85 // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:26-[[@LINE-6]]:26}:")"
87 (void)(i && i || 0);
88 #ifndef SILENCE
89 // expected-warning@-2 {{'&&' within '||'}}
90 // expected-note@-3 {{place parentheses around the '&&' expression to silence this warning}}
91 #endif
92 // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:10-[[@LINE-5]]:10}:"("
93 // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:16-[[@LINE-6]]:16}:")"
94 (void)(0 || i && i);
95 #ifndef SILENCE
96 // expected-warning@-2 {{'&&' within '||'}}
97 // expected-note@-3 {{place parentheses around the '&&' expression to silence this warning}}
98 #endif
99 // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:15-[[@LINE-5]]:15}:"("
100 // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:21-[[@LINE-6]]:21}:")"