Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Anders Carlsson | b88d45e | 2008-08-23 21:12:35 +0000 | [diff] [blame] | 2 | |
| 3 | // Bool literals can be enum values. |
| 4 | enum { |
| 5 | ReadWrite = false, |
| 6 | ReadOnly = true |
| 7 | }; |
Sebastian Redl | e6d5a4a | 2008-12-20 09:35:34 +0000 | [diff] [blame] | 8 | |
| 9 | // bool cannot be decremented, and gives a warning on increment |
| 10 | void test(bool b) |
| 11 | { |
| 12 | ++b; // expected-warning {{incrementing expression of type bool is deprecated}} |
| 13 | b++; // expected-warning {{incrementing expression of type bool is deprecated}} |
| 14 | --b; // expected-error {{cannot decrement expression of type bool}} |
| 15 | b--; // expected-error {{cannot decrement expression of type bool}} |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 16 | |
Eli Friedman | cfdc81a | 2009-12-19 08:11:05 +0000 | [diff] [blame] | 17 | bool *b1 = (int *)0; // expected-error{{cannot initialize}} |
Sebastian Redl | e6d5a4a | 2008-12-20 09:35:34 +0000 | [diff] [blame] | 18 | } |
Anders Carlsson | 0490501 | 2009-10-16 01:44:21 +0000 | [diff] [blame] | 19 | |
| 20 | // static_assert_arg_is_bool(x) compiles only if x is a bool. |
| 21 | template <typename T> |
| 22 | void static_assert_arg_is_bool(T x) { |
| 23 | bool* p = &x; |
| 24 | } |
| 25 | |
| 26 | void test2() { |
| 27 | int n = 2; |
Chris Lattner | 90a8f27 | 2010-07-13 19:41:32 +0000 | [diff] [blame] | 28 | static_assert_arg_is_bool(n && 4); // expected-warning {{use of logical && with constant operand}} |
| 29 | static_assert_arg_is_bool(n || 5); // expected-warning {{use of logical || with constant operand}} |
Anders Carlsson | 0490501 | 2009-10-16 01:44:21 +0000 | [diff] [blame] | 30 | } |