brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 0f4d9f9 Raw
42 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify -Wtautological-negation-compare -Wno-constant-logical-operand %s2// RUN: %clang_cc1 -fsyntax-only -verify -Wtautological-compare -Wno-constant-logical-operand %s3// RUN: %clang_cc1 -fsyntax-only -verify -Wall -Wno-unused -Wno-loop-analysis -Wno-constant-logical-operand %s4 5#define COPY(x) x6 7void 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}}12 13  // parentheses are ignored14  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}}16 17  // don't warn on macros18  if (COPY(x) || !x) {}19  if (!x || COPY(x)) {}20  if (x && COPY(!x)) {}21  if (COPY(!x && x)) {}22 23  // dont' warn on literals24  if (1 || !1) {}25  if (!42 && 42) {}26 27 28  // don't warn on overloads29  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; }34  };35 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}}41}42