blob: 69c0119357814e065953083cb30697c8bf558153 [file] [log] [blame]
David Blaikiebe0ee872012-05-15 16:56:36 +00001// RUN: %clang_cc1 -fsyntax-only -verify -Wno-constant-conversion %s
Richard Trieuf58443e2013-08-08 03:05:52 +00002// RUN: %clang_cc1 -fsyntax-only -verify -Wno-constant-conversion \
3// RUN: -Wno-deprecated -Wdeprecated-increment-bool %s
Anders Carlssonb88d45e2008-08-23 21:12:35 +00004
5// Bool literals can be enum values.
6enum {
7 ReadWrite = false,
8 ReadOnly = true
9};
Sebastian Redle6d5a4a2008-12-20 09:35:34 +000010
11// bool cannot be decremented, and gives a warning on increment
12void 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}}
Douglas Gregord249e1d1f2009-05-29 20:38:28 +000018
Eli Friedmancfdc81a2009-12-19 08:11:05 +000019 bool *b1 = (int *)0; // expected-error{{cannot initialize}}
Sebastian Redle6d5a4a2008-12-20 09:35:34 +000020}
Anders Carlsson04905012009-10-16 01:44:21 +000021
22// static_assert_arg_is_bool(x) compiles only if x is a bool.
23template <typename T>
24void static_assert_arg_is_bool(T x) {
25 bool* p = &x;
26}
27
28void test2() {
29 int n = 2;
Matt Beaumont-Gay9b127f32011-08-15 17:50:06 +000030 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}}
Anders Carlsson04905012009-10-16 01:44:21 +000035}