1 // RUN: %clang_cc1 %s -verify -Wobjc-signed-char-bool
2 // RUN: %clang_cc1 -xobjective-c++ %s -verify -Wobjc-signed-char-bool
4 typedef signed char BOOL;
8 typedef unsigned char Boolean;
18 b = fl; // expected-warning {{implicit conversion from floating-point type 'float' to 'BOOL'}}
19 b = i; // expected-warning {{implicit conversion from integral type 'int' to 'BOOL'}}
23 b = 1.1; // expected-warning {{implicit conversion from 'double' to 'BOOL' (aka 'signed char') changes value from 1.1 to 1}}
24 b = 2.1; // expected-warning {{implicit conversion from constant value 2.1 to 'BOOL'; the only well defined values for 'BOOL' are YES and NO}}
27 b = ptr; // expected-error {{incompatible pointer to integer conversion assigning to 'BOOL' (aka 'signed char') from 'int *'}}
34 void t2(BoolProp *bp) {
38 bp.p = fl; // expected-warning {{implicit conversion from floating-point type 'float' to 'BOOL'}}
39 bp.p = i; // expected-warning {{implicit conversion from integral type 'int' to 'BOOL'}}
42 bp.p = ptr; // expected-error {{incompatible pointer to integer conversion assigning to 'BOOL' (aka 'signed char') from 'int *'}}
44 bp.p = 2; // expected-warning {{implicit conversion from constant value 2 to 'BOOL'; the only well defined values for 'BOOL' are YES and NO}}
50 unsigned unsigned_bf1 : 1;
51 unsigned unsigned_bf2 : 2;
53 struct has_bf *nested;
56 void t3(struct has_bf *bf) {
57 b = bf->signed_bf1; // expected-warning{{implicit conversion from integral type 'int' to 'BOOL'}}
58 b = bf->signed_bf2; // expected-warning{{implicit conversion from integral type 'int' to 'BOOL'}}
59 b = bf->unsigned_bf1; // no warning
60 b = bf->unsigned_bf2; // expected-warning{{implicit conversion from integral type 'unsigned int' to 'BOOL'}}
62 b = local.unsigned_bf1;
63 b = local.unsigned_bf2; // expected-warning{{implicit conversion from integral type 'unsigned int' to 'BOOL'}}
64 b = local.nested->unsigned_bf1;
65 b = local.nested->unsigned_bf2; // expected-warning{{implicit conversion from integral type 'unsigned int' to 'BOOL'}}
68 void t4(BoolProp *bp) {
70 bp.p = 1 ? local : NO; // no warning
73 __attribute__((objc_root_class))
76 unsigned unsigned_bf1 : 1;
77 unsigned unsigned_bf2 : 2;
81 @implementation BFIvar
84 b = bf.unsigned_bf2; // expected-warning{{implicit conversion from integral type 'unsigned int' to 'BOOL'}}
86 b = unsigned_bf2; // expected-warning{{implicit conversion from integral type 'unsigned int' to 'BOOL'}}
93 unsigned i : sizeof(T);
99 BOOL b = i.i; // expected-warning{{implicit conversion from integral type 'unsigned int' to 'BOOL'}}
104 f<short>(); // expected-note {{in instantiation of function template specialization 'f<short>' requested here}}
110 b = b ?: YES; // no warning
111 b = b ?: i; // expected-warning {{implicit conversion from integral type 'int' to 'BOOL'}}
112 b = (b = i) // expected-warning {{implicit conversion from integral type 'int' to 'BOOL'}}
114 b = (1 ? YES : i) ?: YES; // expected-warning {{implicit conversion from integral type 'int' to 'BOOL'}}
115 b = b ?: (1 ? i : i); // expected-warning 2 {{implicit conversion from integral type 'int' to 'BOOL'}}
117 b = b ? YES : (i ?: 0); // expected-warning {{implicit conversion from integral type 'int' to 'BOOL'}}