diff options
| author | Erik Pilkington <erik.pilkington@gmail.com> | 2019-09-17 21:11:51 +0000 |
|---|---|---|
| committer | Erik Pilkington <erik.pilkington@gmail.com> | 2019-09-17 21:11:51 +0000 |
| commit | 5c62152275c0642fb687af1f604b7a60aed82a7e (patch) | |
| tree | 7085c9fc8733a016f78e7a552afcadb2395d0515 /clang/test/SemaObjC | |
| parent | 23e872a3d0548dac30b5d282506198dddfe89b2a (diff) | |
| download | bcm5719-llvm-5c62152275c0642fb687af1f604b7a60aed82a7e.tar.gz bcm5719-llvm-5c62152275c0642fb687af1f604b7a60aed82a7e.zip | |
[Sema] Split of versions of -Wimplicit-{float,int}-conversion for Objective-C BOOL
Also, add a diagnostic group, -Wobjc-signed-char-bool, to control all these
related diagnostics.
rdar://51954400
Differential revision: https://reviews.llvm.org/D67559
llvm-svn: 372183
Diffstat (limited to 'clang/test/SemaObjC')
| -rw-r--r-- | clang/test/SemaObjC/signed-char-bool-conversion.m | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/clang/test/SemaObjC/signed-char-bool-conversion.m b/clang/test/SemaObjC/signed-char-bool-conversion.m new file mode 100644 index 00000000000..476ecc6a060 --- /dev/null +++ b/clang/test/SemaObjC/signed-char-bool-conversion.m @@ -0,0 +1,49 @@ +// RUN: %clang_cc1 %s -verify -Wobjc-signed-char-bool +// RUN: %clang_cc1 -xobjective-c++ %s -verify -Wobjc-signed-char-bool + +typedef signed char BOOL; +#define YES __objc_yes +#define NO __objc_no + +typedef unsigned char Boolean; + +BOOL b; +Boolean boolean; +float fl; +int i; +int *ptr; + +void t1() { + b = boolean; + b = fl; // expected-warning {{implicit conversion from floating-point type 'float' to 'BOOL'}} + b = i; // expected-warning {{implicit conversion from integral type 'int' to 'BOOL'}} + + b = 1.0; + b = 0.0; + b = 1.1; // expected-warning {{implicit conversion from 'double' to 'BOOL' (aka 'signed char') changes value from 1.1 to 1}} + 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}} + + b = YES; +#ifndef __cplusplus + b = ptr; // expected-warning {{incompatible pointer to integer conversion assigning to 'BOOL' (aka 'signed char') from 'int *'}} +#endif +} + +@interface BoolProp +@property BOOL p; +@end + +void t2(BoolProp *bp) { + bp.p = YES; + bp.p = NO; + bp.p = boolean; + bp.p = fl; // expected-warning {{implicit conversion from floating-point type 'float' to 'BOOL'}} + bp.p = i; // expected-warning {{implicit conversion from integral type 'int' to 'BOOL'}} + bp.p = b; + bp.p = bp.p; +#ifndef __cplusplus + bp.p = ptr; // expected-warning {{incompatible pointer to integer conversion assigning to 'BOOL' (aka 'signed char') from 'int *'}} +#endif + bp.p = 1; + bp.p = 2; // expected-warning {{implicit conversion from constant value 2 to 'BOOL'; the only well defined values for 'BOOL' are YES and NO}} +} |

