Erik Pilkington | 5c62152 | 2019-09-17 21:11:51 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -verify -Wobjc-signed-char-bool |
| 2 | // RUN: %clang_cc1 -xobjective-c++ %s -verify -Wobjc-signed-char-bool |
| 3 | |
| 4 | typedef signed char BOOL; |
| 5 | #define YES __objc_yes |
| 6 | #define NO __objc_no |
| 7 | |
| 8 | typedef unsigned char Boolean; |
| 9 | |
| 10 | BOOL b; |
| 11 | Boolean boolean; |
| 12 | float fl; |
| 13 | int i; |
| 14 | int *ptr; |
| 15 | |
| 16 | void 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 | |
| 36 | void 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 | } |