Debian Codegraph @

clang/test/SemaObjC/comptypes-7.m

raw
1 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
2
3 #define nil (void *)0;
4
5 extern void foo(void);
6
7 @protocol MyProtocol
8 - (void) method;
9 @end
10
11 @interface MyClass
12 @end
13
14 int main(void)
15 {
16 id obj = nil;
17 id <MyProtocol> obj_p = nil;
18 MyClass *obj_c = nil;
19 Class obj_C = nil;
20
21 int i = 0;
22 int *j = nil;
23
24 /* The incompatible pointer types should all generate warnings, while the
25 incompatible integer to/from pointer conversions default to an error. */
26
27 obj = i; // expected-error {{incompatible integer to pointer conversion assigning to 'id' from 'int'}}
28 obj = j; // expected-error {{incompatible pointer types assigning to 'id' from 'int *'}}
29
30 obj_p = i; // expected-error {{incompatible integer to pointer conversion assigning to 'id<MyProtocol>' from 'int'}}
31 obj_p = j; // expected-error {{incompatible pointer types assigning to 'id<MyProtocol>' from 'int *'}}
32
33 obj_c = i; // expected-error {{incompatible integer to pointer conversion assigning to 'MyClass *' from 'int'}}
34 obj_c = j; // expected-error {{incompatible pointer types assigning to 'MyClass *' from 'int *'}}
35
36 obj_C = i; // expected-error {{incompatible integer to pointer conversion assigning to 'Class' from 'int'}}
37 obj_C = j; // expected-error {{incompatible pointer types assigning to 'Class' from 'int *'}}
38
39 i = obj; // expected-error {{incompatible pointer to integer conversion assigning to 'int' from 'id'}}
40 i = obj_p; // expected-error {{incompatible pointer to integer conversion assigning to 'int' from 'id<MyProtocol>'}}
41 i = obj_c; // expected-error {{incompatible pointer to integer conversion assigning to 'int' from 'MyClass *'}}
42 i = obj_C; // expected-error {{incompatible pointer to integer conversion assigning to 'int' from 'Class'}}
43
44 j = obj; // expected-error {{incompatible pointer types assigning to 'int *' from 'id'}}
45 j = obj_p; // expected-error {{incompatible pointer types assigning to 'int *' from 'id<MyProtocol>'}}
46 j = obj_c; // expected-error {{incompatible pointer types assigning to 'int *' from 'MyClass *'}}
47 j = obj_C; // expected-error {{incompatible pointer types assigning to 'int *' from 'Class'}}
48
49 if (obj == i) foo() ; // expected-warning {{comparison between pointer and integer ('id' and 'int')}}
50 if (i == obj) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'id')}}
51 if (obj == j) foo() ; // expected-warning {{comparison of distinct pointer types ('id' and 'int *')}}
52 if (j == obj) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'id')}}
53
54 if (obj_c == i) foo() ; // expected-warning {{comparison between pointer and integer ('MyClass *' and 'int')}}
55 if (i == obj_c) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'MyClass *')}}
56 if (obj_c == j) foo() ; // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'int *')}}
57 if (j == obj_c) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'MyClass *')}}
58
59 if (obj_p == i) foo() ; // expected-warning {{comparison between pointer and integer ('id<MyProtocol>' and 'int')}}
60 if (i == obj_p) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'id<MyProtocol>')}}
61 if (obj_p == j) foo() ; // expected-warning {{comparison of distinct pointer types ('id<MyProtocol>' and 'int *')}}
62 if (j == obj_p) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'id<MyProtocol>')}}
63
64 if (obj_C == i) foo() ; // expected-warning {{comparison between pointer and integer ('Class' and 'int')}}
65 if (i == obj_C) foo() ; // expected-warning {{comparison between pointer and integer ('int' and 'Class')}}
66 if (obj_C == j) foo() ; // expected-warning {{comparison of distinct pointer types ('Class' and 'int *')}}
67 if (j == obj_C) foo() ; // expected-warning {{comparison of distinct pointer types ('int *' and 'Class')}}
68
69 Class bar1 = nil;
70 Class <MyProtocol> bar = nil;
71 bar = bar1;
72 bar1 = bar;
73
74 return 0;
75 }