1 // 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
12 typedef bool boolean;
13 #else
14 typedef _Bool boolean;
15 #endif
16 
test(boolean a)17 void 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'}}
21   r = a ? -2 : 0;
22   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 }
33