43 lines · cpp
1// RUN: %clang_cc1 %std_cxx98-14 -fsyntax-only -verify=expected,precxx17 -Wno-constant-conversion %s2// RUN: %clang_cc1 %std_cxx98-14 -fsyntax-only -verify=expected,precxx17 -Wno-constant-conversion -Wno-deprecated -Wdeprecated-increment-bool %s3// RUN: %clang_cc1 %std_cxx17- -fsyntax-only -verify=expected,cxx17 -Wno-constant-conversion -Wno-deprecated -Wdeprecated-increment-bool %s4 5// RUN: %clang_cc1 %std_cxx98-14 -fsyntax-only -verify=expected,precxx17 -Wno-constant-conversion %s -fexperimental-new-constant-interpreter6// RUN: %clang_cc1 %std_cxx98-14 -fsyntax-only -verify=expected,precxx17 -Wno-constant-conversion -Wno-deprecated -Wdeprecated-increment-bool %s -fexperimental-new-constant-interpreter7// RUN: %clang_cc1 %std_cxx17- -fsyntax-only -verify=expected,cxx17 -Wno-constant-conversion -Wno-deprecated -Wdeprecated-increment-bool %s -fexperimental-new-constant-interpreter8 9 10// Bool literals can be enum values.11enum {12 ReadWrite = false,13 ReadOnly = true14};15 16// bool cannot be decremented, and gives a warning on increment17void test(bool b)18{19 ++b; // precxx17-warning {{incrementing expression of type bool is deprecated}} \20 cxx17-error {{ISO C++17 does not allow incrementing expression of type bool}}21 b++; // precxx17-warning {{incrementing expression of type bool is deprecated}} \22 cxx17-error {{ISO C++17 does not allow incrementing expression of type bool}}23 --b; // expected-error {{cannot decrement expression of type bool}}24 b--; // expected-error {{cannot decrement expression of type bool}}25 26 bool *b1 = (int *)0; // expected-error{{cannot initialize}}27}28 29// static_assert_arg_is_bool(x) compiles only if x is a bool.30template <typename T>31void static_assert_arg_is_bool(T x) {32 bool* p = &x;33}34 35void test2() {36 int n = 2;37 static_assert_arg_is_bool(n && 4); // expected-warning {{use of logical '&&' with constant operand}} \38 // expected-note {{use '&' for a bitwise operation}} \39 // expected-note {{remove constant to silence this warning}}40 static_assert_arg_is_bool(n || 5); // expected-warning {{use of logical '||' with constant operand}} \41 // expected-note {{use '|' for a bitwise operation}}42}43