blob: 397a471257037775be5d77eaafe36d8101c03c2b [file] [log] [blame]
Douglas Gregord6fb7ef2008-12-18 19:37:40 +00001// RUN: clang -fsyntax-only -verify %s
Douglas Gregordda78892008-12-18 23:43:31 +00002@interface Foo
3@end
4
5@implementation Foo
6
7void func(id);
8
9+ zone {
10 func(self);
11 return self;
12}
Douglas Gregora46969d2008-12-19 19:16:37 +000013@end
Douglas Gregordda78892008-12-18 23:43:31 +000014
Douglas Gregor7ca09762008-11-27 01:19:21 +000015@protocol P0
16@end
17
18@protocol P1
19@end
20
21@interface A <P0>
Douglas Gregorcb7de522008-11-26 23:31:11 +000022@end
23
24@interface B : A
25@end
26
Douglas Gregor7ca09762008-11-27 01:19:21 +000027@interface C <P1>
28@end
29
Douglas Gregorcb7de522008-11-26 23:31:11 +000030int& f(A*);
31float& f(B*);
32void g(A*);
33
34int& h(A*);
35float& h(id);
36
37void test(A* a, B* b, id val) {
38 int& i1 = f(a);
39 float& f1 = f(b);
40 float& f2 = f(val);
41 g(a);
42 g(b);
43 g(val);
44 int& i2 = h(a);
45 float& f3 = h(val);
46 // int& i3 = h(b); FIXME: we match GCC here, but shouldn't this work?
47}
48
Douglas Gregorc7887512008-12-19 19:13:09 +000049void downcast_test(A* a, A** ap) {
Douglas Gregor45920e82008-12-19 17:40:08 +000050 B* b = a; // expected-warning{{incompatible pointer types initializing 'B *', expected 'A *'}}
51 b = a; // expected-warning{{incompatible pointer types assigning 'B *', expected 'A *'}}
Douglas Gregorc7887512008-12-19 19:13:09 +000052
53 B** bp = ap; // expected-warning{{incompatible pointer types initializing 'B **', expected 'A **'}}
54 bp = ap; // expected-warning{{incompatible pointer types assigning 'B **', expected 'A **'}}
Douglas Gregor45920e82008-12-19 17:40:08 +000055}
56
Douglas Gregorcb7de522008-11-26 23:31:11 +000057int& cv(A*);
58float& cv(const A*);
59int& cv2(void*);
60float& cv2(const void*);
61
62void cv_test(A* a, B* b, const A* ac, const B* bc) {
63 int &i1 = cv(a);
64 int &i2 = cv(b);
65 float &f1 = cv(ac);
66 float &f2 = cv(bc);
67 int& i3 = cv2(a);
68 float& f3 = cv2(ac);
69}
Douglas Gregor7ca09762008-11-27 01:19:21 +000070
71
72int& qualid(id<P0>);
73float& qualid(id<P1>); // FIXME: GCC complains that this isn't an overload. Is it?
74
75void qualid_test(A *a, B *b, C *c) {
76 int& i1 = qualid(a);
77 int& i2 = qualid(b);
78 float& f1 = qualid(c);
Douglas Gregor27b09ac2008-12-22 20:51:52 +000079
80 id<P0> p1 = 0;
81 p1 = 0;
Douglas Gregor7ca09762008-11-27 01:19:21 +000082}
Douglas Gregorc7887512008-12-19 19:13:09 +000083
84
85@class NSException;
86typedef struct {
87 void (*throw_exc)(id);
88}
89objc_exception_functions_t;
90
91void (*_NSExceptionRaiser(void))(NSException *) {
92 objc_exception_functions_t exc_funcs;
93 return exc_funcs.throw_exc; // expected-warning{{incompatible pointer types returning 'void (*)(NSException *)', expected 'void (*)(id)'}}
94}