blob: 476ecc6a0603cec6c783857e1a3cfd567df404e1 [file] [log] [blame]
Erik Pilkington5c621522019-09-17 21:11:51 +00001// RUN: %clang_cc1 %s -verify -Wobjc-signed-char-bool
2// RUN: %clang_cc1 -xobjective-c++ %s -verify -Wobjc-signed-char-bool
3
4typedef signed char BOOL;
5#define YES __objc_yes
6#define NO __objc_no
7
8typedef unsigned char Boolean;
9
10BOOL b;
11Boolean boolean;
12float fl;
13int i;
14int *ptr;
15
16void t1() {
17 b = 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'}}
20
21 b = 1.0;
22 b = 0.0;
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}}
25
26 b = YES;
27#ifndef __cplusplus
28 b = ptr; // expected-warning {{incompatible pointer to integer conversion assigning to 'BOOL' (aka 'signed char') from 'int *'}}
29#endif
30}
31
32@interface BoolProp
33@property BOOL p;
34@end
35
36void t2(BoolProp *bp) {
37 bp.p = YES;
38 bp.p = NO;
39 bp.p = boolean;
40 bp.p = fl; // expected-warning {{implicit conversion from floating-point type 'float' to 'BOOL'}}
41 bp.p = i; // expected-warning {{implicit conversion from integral type 'int' to 'BOOL'}}
42 bp.p = b;
43 bp.p = bp.p;
44#ifndef __cplusplus
45 bp.p = ptr; // expected-warning {{incompatible pointer to integer conversion assigning to 'BOOL' (aka 'signed char') from 'int *'}}
46#endif
47 bp.p = 1;
48 bp.p = 2; // expected-warning {{implicit conversion from constant value 2 to 'BOOL'; the only well defined values for 'BOOL' are YES and NO}}
49}