1 // RUN: %clang_cc1 -fsyntax-only -verify -Wtautological-negation-compare -Wno-constant-logical-operand %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -Wtautological-compare -Wno-constant-logical-operand %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -Wall -Wno-unused -Wno-loop-analysis -Wno-constant-logical-operand %s
8 if (x
|| !x
) {} // expected-warning {{'||' of a value and its negation always evaluates to true}}
9 if (!x
|| x
) {} // expected-warning {{'||' of a value and its negation always evaluates to true}}
10 if (x
&& !x
) {} // expected-warning {{'&&' of a value and its negation always evaluates to false}}
11 if (!x
&& x
) {} // expected-warning {{'&&' of a value and its negation always evaluates to false}}
13 // parentheses are ignored
14 if (x
|| (!x
)) {} // expected-warning {{'||' of a value and its negation always evaluates to true}}
15 if (!(x
) || x
) {} // expected-warning {{'||' of a value and its negation always evaluates to true}}
17 // don't warn on macros
23 // dont' warn on literals
28 // don't warn on overloads
31 Foo
operator!() const { return Foo
{!val
}; }
32 bool operator||(const Foo other
) const { return val
|| other
.val
; }
33 bool operator&&(const Foo other
) const { return val
&& other
.val
; }
39 if (f
.val
|| !f
.val
) {} // expected-warning {{'||' of a value and its negation always evaluates to true}}
40 if (!f
.val
&& f
.val
) {} // expected-warning {{'&&' of a value and its negation always evaluates to false}}