Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaCXX / tautological-negation-compare.cpp
blob0f4d9f9842c252b84315bf2d9b4b98fd26e3d271
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
5 #define COPY(x) x
7 void test_int(int x) {
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
18 if (COPY(x) || !x) {}
19 if (!x || COPY(x)) {}
20 if (x && COPY(!x)) {}
21 if (COPY(!x && x)) {}
23 // dont' warn on literals
24 if (1 || !1) {}
25 if (!42 && 42) {}
28 // don't warn on overloads
29 struct Foo{
30 int val;
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; }
36 Foo f{3};
37 if (f || !f) {}
38 if (!f || f) {}
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}}