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
5
6 #ifdef SILENCE
7 // expected-no-diagnostics
8 #endif
9
logical_op_parentheses(unsigned i)10 void logical_op_parentheses(unsigned i) {
11 (void)(i ||
12 i && i);
13 #ifndef SILENCE
14 // expected-warning@-2 {{'&&' within '||'}}
15 // expected-note@-3 {{place parentheses around the '&&' expression to silence this warning}}
16 #endif
17 // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:14-[[@LINE-5]]:14}:"("
18 // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:20-[[@LINE-6]]:20}:")"
19
20 (void)(i || i && "w00t");
21 (void)("w00t" && i || i);
22
23 (void)(i || i && "w00t" || i);
24 #ifndef SILENCE
25 // expected-warning@-2 {{'&&' within '||'}}
26 // expected-note@-3 {{place parentheses around the '&&' expression to silence this warning}}
27 #endif
28 // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:15-[[@LINE-5]]:15}:"("
29 // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:26-[[@LINE-6]]:26}:")"
30
31 (void)(i || "w00t" && i || i);
32 #ifndef SILENCE
33 // expected-warning@-2 {{'&&' within '||'}}
34 // expected-note@-3 {{place parentheses around the '&&' expression to silence this warning}}
35 #endif
36 // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:15-[[@LINE-5]]:15}:"("
37 // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:26-[[@LINE-6]]:26}:")"
38
39 (void)(i && i || 0);
40 (void)(0 || i && i);
41 }
42