| 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-constant-conversion %s |
| 2 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-constant-conversion \ |
| 3 | // RUN: -Wno-deprecated -Wdeprecated-increment-bool %s |
| 4 | |
| 5 | // Bool literals can be enum values. |
| 6 | enum { |
| 7 | ReadWrite = false, |
| 8 | ReadOnly = true |
| 9 | }; |
| 10 | |
| 11 | // bool cannot be decremented, and gives a warning on increment |
| 12 | void test(bool b) |
| 13 | { |
| 14 | ++b; // expected-warning {{incrementing expression of type bool is deprecated}} |
| 15 | b++; // expected-warning {{incrementing expression of type bool is deprecated}} |
| 16 | --b; // expected-error {{cannot decrement expression of type bool}} |
| 17 | b--; // expected-error {{cannot decrement expression of type bool}} |
| 18 | |
| 19 | bool *b1 = (int *)0; // expected-error{{cannot initialize}} |
| 20 | } |
| 21 | |
| 22 | // static_assert_arg_is_bool(x) compiles only if x is a bool. |
| 23 | template <typename T> |
| 24 | void static_assert_arg_is_bool(T x) { |
| 25 | bool* p = &x; |
| 26 | } |
| 27 | |
| 28 | void test2() { |
| 29 | int n = 2; |
| 30 | static_assert_arg_is_bool(n && 4); // expected-warning {{use of logical '&&' with constant operand}} \ |
| 31 | // expected-note {{use '&' for a bitwise operation}} \ |
| 32 | // expected-note {{remove constant to silence this warning}} |
| 33 | static_assert_arg_is_bool(n || 5); // expected-warning {{use of logical '||' with constant operand}} \ |
| 34 | // expected-note {{use '|' for a bitwise operation}} |
| 35 | } |
| 36 | |