blob: eb313df029b7ac1ed0a49ce9264529156209f024 [file] [log] [blame]
Daniel Dunbar40727a42008-09-03 17:53:25 +00001// RUN: clang -fsyntax-only -verify %s
2
3@protocol P0
4@end
5@protocol P1
6@end
7@protocol P2
8@end
9
10@interface A <P0>
11@end
12
13@interface B : A
14@end
15
16void bar(id x);
17void barP0(id<P0> x);
18void barP1(id<P1> x);
19void barP2(id<P2> x);
20
21void f0(A *a) {
22 id l = a;
23}
24
25void f1(id x, A *a) {
26 id<P0> l = a;
27}
28
29void f2(id<P1> x) {
Steve Naroff39579072008-10-14 22:18:38 +000030 id<P0> l = x; // expected-warning {{incompatible type initializing 'id<P1>', expected 'id<P0>'}}
Daniel Dunbar40727a42008-09-03 17:53:25 +000031}
32
33void f3(A *a) {
Steve Naroff39579072008-10-14 22:18:38 +000034 id<P1> l = a; // expected-warning {{incompatible type initializing 'A *', expected 'id<P1>'}}
Daniel Dunbar40727a42008-09-03 17:53:25 +000035}
36
37void f4(int cond, id x, A *a) {
38 bar(cond ? x : a);
39}
40
41void f5(int cond, A *a, B *b) {
42 bar(cond ? a : b);
43}
44
45void f6(int cond, id x, A *a) {
46 bar(cond ? (id<P0, P1>) x : a);
47}
48
49void f7(int cond, id x, A *a) {
50 bar(cond ? a : (id<P0, P1>) x);
51}
52
53void f8(int cond, id<P0,P1> x0, id<P0,P2> x1) {
54 barP0(cond ? x0 : x1);
55}
56
57void f9(int cond, id<P0,P1> x0, id<P0,P2> x1) {
58 barP1(cond ? x0 : x1);
59}
60
61void f10(int cond, id<P0,P1> x0, id<P0,P2> x1) {
62 barP2(cond ? x0 : x1);
63}
Douglas Gregor7ffd0de2008-11-26 06:43:45 +000064
65int f11(int cond, A* a, B* b) {
66 return (cond? b : a)->x; // expected-error{{'A' does not have a member named 'x'}}
67}