1// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3#define nil (void *)0;
4
5extern void foo();
6
7@protocol MyProtocolA
8- (void) methodA;
9@end
10
11@protocol MyProtocolB
12- (void) methodB;
13@end
14
15@protocol MyProtocolAB <MyProtocolA, MyProtocolB>
16@end
17
18@protocol MyProtocolAC <MyProtocolA>
19- (void) methodC;
20@end
21
22int main()
23{
24  id<MyProtocolA> obj_a = nil;
25  id<MyProtocolB> obj_b = nil;
26  id<MyProtocolAB> obj_ab = nil;
27  id<MyProtocolAC> obj_ac = nil;
28
29  obj_a = obj_b;  // expected-warning {{assigning to 'id<MyProtocolA>' from incompatible type 'id<MyProtocolB>'}}
30  obj_a = obj_ab; /* Ok */
31  obj_a = obj_ac; /* Ok */
32
33  obj_b = obj_a;  // expected-warning {{assigning to 'id<MyProtocolB>' from incompatible type 'id<MyProtocolA>'}}
34  obj_b = obj_ab; /* Ok */
35  obj_b = obj_ac; // expected-warning {{assigning to 'id<MyProtocolB>' from incompatible type 'id<MyProtocolAC>'}}
36
37  obj_ab = obj_a;  // expected-warning {{assigning to 'id<MyProtocolAB>' from incompatible type 'id<MyProtocolA>'}}
38  obj_ab = obj_b;  // expected-warning {{assigning to 'id<MyProtocolAB>' from incompatible type 'id<MyProtocolB>'}}
39  obj_ab = obj_ac; // expected-warning {{assigning to 'id<MyProtocolAB>' from incompatible type 'id<MyProtocolAC>'}}
40
41  obj_ac = obj_a;  // expected-warning {{assigning to 'id<MyProtocolAC>' from incompatible type 'id<MyProtocolA>'}}
42  obj_ac = obj_b;  // expected-warning {{assigning to 'id<MyProtocolAC>' from incompatible type 'id<MyProtocolB>'}}
43  obj_ac = obj_ab; // expected-warning {{assigning to 'id<MyProtocolAC>' from incompatible type 'id<MyProtocolAB>'}}
44
45  if (obj_a == obj_b) foo (); // expected-warning {{comparison of distinct pointer types ('id<MyProtocolA>' and 'id<MyProtocolB>')}}
46  if (obj_b == obj_a) foo (); // expected-warning {{comparison of distinct pointer types ('id<MyProtocolB>' and 'id<MyProtocolA>')}}
47
48  if (obj_a == obj_ab) foo (); /* Ok */
49  if (obj_ab == obj_a) foo (); /* Ok */
50
51  if (obj_a == obj_ac) foo (); /* Ok */
52  if (obj_ac == obj_a) foo (); /* Ok */
53
54  if (obj_b == obj_ab) foo (); /* Ok */
55  if (obj_ab == obj_b) foo (); /* Ok */
56
57  if (obj_b == obj_ac) foo (); // expected-warning {{comparison of distinct pointer types ('id<MyProtocolB>' and 'id<MyProtocolAC>')}}
58  if (obj_ac == obj_b) foo (); // expected-warning {{comparison of distinct pointer types ('id<MyProtocolAC>' and 'id<MyProtocolB>')}}
59
60  if (obj_ab == obj_ac) foo (); // expected-warning {{comparison of distinct pointer types ('id<MyProtocolAB>' and 'id<MyProtocolAC>')}}
61  if (obj_ac == obj_ab) foo (); // expected-warning {{comparison of distinct pointer types ('id<MyProtocolAC>' and 'id<MyProtocolAB>')}}
62
63  return 0;
64}
65