blob: 95c78d272794ef3f171d92bb558789c1abb36bdf [file] [log] [blame]
David Bolvanskyfb218172019-09-22 22:00:48 +00001// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wtautological-constant-compare %s
2// RUN: %clang_cc1 -x c -fsyntax-only -verify %s
3// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wtautological-constant-compare %s
4// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s
5
6#define ONE 1
7#define TWO 2
8
9#define TERN(c, l, r) c ? l : r
10
11#ifdef __cplusplus
12typedef bool boolean;
13#else
14typedef _Bool boolean;
15#endif
16
17void test(boolean a) {
18 boolean r;
19 r = a ? (1) : TWO;
20 r = a ? 3 : TWO; // expected-warning {{converting the result of '?:' with integer constants to a boolean always evaluates to 'true'}}
Yuanfang Chen442ddff2019-10-04 21:37:20 +000021 r = a ? -2 : 0;
David Bolvanskyfb218172019-09-22 22:00:48 +000022 r = a ? 3 : -2; // expected-warning {{converting the result of '?:' with integer constants to a boolean always evaluates to 'true'}}
23 r = a ? 0 : TWO;
24 r = a ? 3 : ONE; // expected-warning {{converting the result of '?:' with integer constants to a boolean always evaluates to 'true'}}
25 r = a ? ONE : 0;
26 r = a ? 0 : -0;
27 r = a ? 1 : 0;
28 r = a ? ONE : 0;
29 r = a ? ONE : ONE;
30 r = TERN(a, 4, 8); // expected-warning {{converting the result of '?:' with integer constants to a boolean always evaluates to 'true'}}
31 r = TERN(a, -1, -8); // expected-warning {{converting the result of '?:' with integer constants to a boolean always evaluates to 'true'}}
32}