[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / clang / test / SemaObjC / signed-char-bool-conversion.m
blob6945d86fc26d17a178ba5411703738883d455972
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;
5 #define YES __objc_yes
6 #define NO __objc_no
8 typedef unsigned char Boolean;
10 BOOL b;
11 Boolean boolean;
12 float fl;
13 int i;
14 int *ptr;
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'}}
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}}
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
32 @interface BoolProp
33 @property BOOL p;
34 @end
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}}
51 struct has_bf {
52   int signed_bf1 : 1;
53   int signed_bf2 : 2;
54   unsigned unsigned_bf1 : 1;
55   unsigned unsigned_bf2 : 2;
57   struct has_bf *nested;
60 void t3(struct has_bf *bf) {
61   b = bf->signed_bf1; // expected-warning{{implicit conversion from integral type 'int' to 'BOOL'}}
62   b = bf->signed_bf2; // expected-warning{{implicit conversion from integral type 'int' to 'BOOL'}}
63   b = bf->unsigned_bf1; // no warning
64   b = bf->unsigned_bf2; // expected-warning{{implicit conversion from integral type 'unsigned int' to 'BOOL'}}
65   struct has_bf local;
66   b = local.unsigned_bf1;
67   b = local.unsigned_bf2; // expected-warning{{implicit conversion from integral type 'unsigned int' to 'BOOL'}}
68   b = local.nested->unsigned_bf1;
69   b = local.nested->unsigned_bf2; // expected-warning{{implicit conversion from integral type 'unsigned int' to 'BOOL'}}
72 __attribute__((objc_root_class))
73 @interface BFIvar {
74   struct has_bf bf;
75   unsigned unsigned_bf1 : 1;
76   unsigned unsigned_bf2 : 2;
78 @end
80 @implementation BFIvar
81 -(void)m {
82   b = bf.unsigned_bf1;
83   b = bf.unsigned_bf2; // expected-warning{{implicit conversion from integral type 'unsigned int' to 'BOOL'}}
84   b = unsigned_bf1;
85   b = unsigned_bf2; // expected-warning{{implicit conversion from integral type 'unsigned int' to 'BOOL'}}
87 @end
89 #ifdef __cplusplus
90 template <class T>
91 struct S {
92   unsigned i : sizeof(T);
95 template <class T>
96 void f() {
97   S<T> i;
98   BOOL b = i.i; // expected-warning{{implicit conversion from integral type 'unsigned int' to 'BOOL'}}
101 int main() {
102   f<char>();
103   f<short>(); // expected-note {{in instantiation of function template specialization 'f<short>' requested here}}
105 #endif