[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Sema / warn-integer-constants-in-ternary.c
blob95c78d272794ef3f171d92bb558789c1abb36bdf
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
6 #define ONE 1
7 #define TWO 2
9 #define TERN(c, l, r) c ? l : r
11 #ifdef __cplusplus
12 typedef bool boolean;
13 #else
14 typedef _Bool boolean;
15 #endif
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'}}