blob: 487a42e1a1103bb6ac491dd16d3f1b33cba1dd8a [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Daniel Dunbard7390212009-11-03 07:25:45 +00002// XFAIL: *
Douglas Gregordda78892008-12-18 23:43:31 +00003@interface Foo
4@end
5
6@implementation Foo
7
8void func(id);
9
10+ zone {
11 func(self);
12 return self;
13}
Douglas Gregora46969d2008-12-19 19:16:37 +000014@end
Douglas Gregordda78892008-12-18 23:43:31 +000015
Douglas Gregor7ca09762008-11-27 01:19:21 +000016@protocol P0
17@end
18
19@protocol P1
20@end
21
22@interface A <P0>
Douglas Gregorcb7de522008-11-26 23:31:11 +000023@end
24
25@interface B : A
26@end
27
Douglas Gregor7ca09762008-11-27 01:19:21 +000028@interface C <P1>
29@end
30
Douglas Gregorcb7de522008-11-26 23:31:11 +000031int& f(A*);
32float& f(B*);
33void g(A*);
34
35int& h(A*);
36float& h(id);
37
38void test(A* a, B* b, id val) {
39 int& i1 = f(a);
40 float& f1 = f(b);
41 float& f2 = f(val);
42 g(a);
43 g(b);
44 g(val);
45 int& i2 = h(a);
46 float& f3 = h(val);
47 // int& i3 = h(b); FIXME: we match GCC here, but shouldn't this work?
48}
49
Douglas Gregorc7887512008-12-19 19:13:09 +000050void downcast_test(A* a, A** ap) {
Douglas Gregor45920e82008-12-19 17:40:08 +000051 B* b = a; // expected-warning{{incompatible pointer types initializing 'B *', expected 'A *'}}
52 b = a; // expected-warning{{incompatible pointer types assigning 'B *', expected 'A *'}}
Douglas Gregorc7887512008-12-19 19:13:09 +000053
54 B** bp = ap; // expected-warning{{incompatible pointer types initializing 'B **', expected 'A **'}}
55 bp = ap; // expected-warning{{incompatible pointer types assigning 'B **', expected 'A **'}}
Douglas Gregor45920e82008-12-19 17:40:08 +000056}
57
Douglas Gregorcb7de522008-11-26 23:31:11 +000058int& cv(A*);
59float& cv(const A*);
60int& cv2(void*);
61float& cv2(const void*);
62
63void cv_test(A* a, B* b, const A* ac, const B* bc) {
64 int &i1 = cv(a);
65 int &i2 = cv(b);
66 float &f1 = cv(ac);
67 float &f2 = cv(bc);
68 int& i3 = cv2(a);
69 float& f3 = cv2(ac);
70}
Douglas Gregor7ca09762008-11-27 01:19:21 +000071
72
73int& qualid(id<P0>);
74float& qualid(id<P1>); // FIXME: GCC complains that this isn't an overload. Is it?
75
76void qualid_test(A *a, B *b, C *c) {
77 int& i1 = qualid(a);
78 int& i2 = qualid(b);
79 float& f1 = qualid(c);
Douglas Gregor27b09ac2008-12-22 20:51:52 +000080
81 id<P0> p1 = 0;
82 p1 = 0;
Douglas Gregor7ca09762008-11-27 01:19:21 +000083}
Douglas Gregorc7887512008-12-19 19:13:09 +000084
85
86@class NSException;
87typedef struct {
88 void (*throw_exc)(id);
89}
90objc_exception_functions_t;
91
92void (*_NSExceptionRaiser(void))(NSException *) {
93 objc_exception_functions_t exc_funcs;
94 return exc_funcs.throw_exc; // expected-warning{{incompatible pointer types returning 'void (*)(NSException *)', expected 'void (*)(id)'}}
95}
John McCallddb0ce72010-06-11 10:04:22 +000096
97namespace test5 {
98 void foo(bool);
99 void foo(void *);
100
101 void test(id p) {
102 foo(p);
103 }
104}