33 lines · c
1// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wtautological-constant-compare %s2// RUN: %clang_cc1 -x c -fsyntax-only -verify %s3// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wtautological-constant-compare %s4// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s5 6#define ONE 17#define TWO 28 9#define TERN(c, l, r) c ? l : r10 11#ifdef __cplusplus12typedef bool boolean;13#else14typedef _Bool boolean;15#endif16 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'}}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