2012-05-16 00:56:36 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-constant-conversion %s
|
2013-08-08 11:05:52 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-constant-conversion \
|
|
|
|
// RUN: -Wno-deprecated -Wdeprecated-increment-bool %s
|
2008-08-24 05:12:35 +08:00
|
|
|
|
|
|
|
// Bool literals can be enum values.
|
|
|
|
enum {
|
|
|
|
ReadWrite = false,
|
|
|
|
ReadOnly = true
|
|
|
|
};
|
2008-12-20 17:35:34 +08:00
|
|
|
|
|
|
|
// bool cannot be decremented, and gives a warning on increment
|
|
|
|
void test(bool b)
|
|
|
|
{
|
|
|
|
++b; // expected-warning {{incrementing expression of type bool is deprecated}}
|
|
|
|
b++; // expected-warning {{incrementing expression of type bool is deprecated}}
|
|
|
|
--b; // expected-error {{cannot decrement expression of type bool}}
|
|
|
|
b--; // expected-error {{cannot decrement expression of type bool}}
|
2009-05-30 04:38:28 +08:00
|
|
|
|
2009-12-19 16:11:05 +08:00
|
|
|
bool *b1 = (int *)0; // expected-error{{cannot initialize}}
|
2008-12-20 17:35:34 +08:00
|
|
|
}
|
2009-10-16 09:44:21 +08:00
|
|
|
|
|
|
|
// static_assert_arg_is_bool(x) compiles only if x is a bool.
|
|
|
|
template <typename T>
|
|
|
|
void static_assert_arg_is_bool(T x) {
|
|
|
|
bool* p = &x;
|
|
|
|
}
|
|
|
|
|
|
|
|
void test2() {
|
|
|
|
int n = 2;
|
2011-08-16 01:50:06 +08:00
|
|
|
static_assert_arg_is_bool(n && 4); // expected-warning {{use of logical '&&' with constant operand}} \
|
|
|
|
// expected-note {{use '&' for a bitwise operation}} \
|
|
|
|
// expected-note {{remove constant to silence this warning}}
|
|
|
|
static_assert_arg_is_bool(n || 5); // expected-warning {{use of logical '||' with constant operand}} \
|
|
|
|
// expected-note {{use '|' for a bitwise operation}}
|
2009-10-16 09:44:21 +08:00
|
|
|
}
|