blob: bb94d9ed92c38663a9f7f177a86a179188b49129 [file] [log] [blame]
Patrick Beardacfbe9e2012-04-06 18:12:22 +00001// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
Douglas Gregor1e57a3f2008-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 Gregor6ab99782008-12-19 19:16:37 +000013@end
Douglas Gregor1e57a3f2008-12-18 23:43:31 +000014
Douglas Gregora29dc052008-11-27 01:19:21 +000015@protocol P0
16@end
17
18@protocol P1
19@end
20
21@interface A <P0>
Douglas Gregor237f96c2008-11-26 23:31:11 +000022@end
23
24@interface B : A
25@end
26
Douglas Gregora29dc052008-11-27 01:19:21 +000027@interface C <P1>
28@end
29
John McCallf28e83a2010-10-26 06:23:29 +000030int& f(A*); // expected-note {{candidate}}
31float& f(B*); // expected-note {{candidate}}
Douglas Gregor237f96c2008-11-26 23:31:11 +000032void g(A*);
33
Douglas Gregor058d3de2011-01-31 18:51:41 +000034int& h(A*);
35float& h(id);
Douglas Gregor237f96c2008-11-26 23:31:11 +000036
John McCallf28e83a2010-10-26 06:23:29 +000037void test0(A* a, B* b, id val) {
Douglas Gregor237f96c2008-11-26 23:31:11 +000038 int& i1 = f(a);
39 float& f1 = f(b);
John McCallf28e83a2010-10-26 06:23:29 +000040
41 // GCC succeeds here, which is clearly ridiculous.
42 float& f2 = f(val); // expected-error {{ambiguous}}
43
Douglas Gregor237f96c2008-11-26 23:31:11 +000044 g(a);
45 g(b);
46 g(val);
47 int& i2 = h(a);
48 float& f3 = h(val);
Douglas Gregor8d6d0672010-12-01 21:43:58 +000049
Douglas Gregor058d3de2011-01-31 18:51:41 +000050 int& i3 = h(b);
Douglas Gregor237f96c2008-11-26 23:31:11 +000051}
52
John McCallf28e83a2010-10-26 06:23:29 +000053void test1(A* a) {
Fariborz Jahanian413e0642011-03-21 19:08:42 +000054 B* b = a; // expected-warning{{incompatible pointer types initializing 'B *' with an expression of type 'A *'}}
Douglas Gregor2720dc62011-06-11 04:42:12 +000055 B *c; c = a; // expected-warning{{incompatible pointer types assigning to 'B *' from 'A *'}}
Douglas Gregor47d3f272008-12-19 17:40:08 +000056}
57
John McCallf28e83a2010-10-26 06:23:29 +000058void test2(A** ap) {
Fariborz Jahanian413e0642011-03-21 19:08:42 +000059 B** bp = ap; // expected-warning{{incompatible pointer types initializing 'B **' with an expression of type 'A **'}}
Douglas Gregor2720dc62011-06-11 04:42:12 +000060 bp = ap; // expected-warning{{incompatible pointer types assigning to 'B **' from 'A **'}}
John McCallf28e83a2010-10-26 06:23:29 +000061}
62
Eli Friedman5f508952013-06-18 22:41:37 +000063int& cv(A*);
64float& cv(const A*);
John McCallf28e83a2010-10-26 06:23:29 +000065
Douglas Gregor8d6d0672010-12-01 21:43:58 +000066int& cv2(void*);
67float& cv2(const void*);
Douglas Gregor237f96c2008-11-26 23:31:11 +000068
69void cv_test(A* a, B* b, const A* ac, const B* bc) {
70 int &i1 = cv(a);
71 int &i2 = cv(b);
Eli Friedman5f508952013-06-18 22:41:37 +000072 float &f1 = cv(ac);
73 float &f2 = cv(bc);
Douglas Gregor8d6d0672010-12-01 21:43:58 +000074 int& i3 = cv2(a);
75 float& f3 = cv2(ac);
Douglas Gregor237f96c2008-11-26 23:31:11 +000076}
Douglas Gregora29dc052008-11-27 01:19:21 +000077
Eli Friedman5f508952013-06-18 22:41:37 +000078int& qualid(id<P0>);
79float& qualid(id<P1>);
Douglas Gregora29dc052008-11-27 01:19:21 +000080
81void qualid_test(A *a, B *b, C *c) {
82 int& i1 = qualid(a);
83 int& i2 = qualid(b);
John McCallf28e83a2010-10-26 06:23:29 +000084
Eli Friedman5f508952013-06-18 22:41:37 +000085 float& f1 = qualid(c);
Douglas Gregor79a6b012008-12-22 20:51:52 +000086
87 id<P0> p1 = 0;
88 p1 = 0;
Douglas Gregora29dc052008-11-27 01:19:21 +000089}
Douglas Gregora119f102008-12-19 19:13:09 +000090
91
92@class NSException;
93typedef struct {
94 void (*throw_exc)(id);
95}
96objc_exception_functions_t;
97
98void (*_NSExceptionRaiser(void))(NSException *) {
99 objc_exception_functions_t exc_funcs;
Douglas Gregor6dd3a6a2010-12-02 21:47:04 +0000100 return exc_funcs.throw_exc; // expected-warning{{incompatible pointer types returning 'void (*)(id)' from a function with result type 'void (*)(NSException *)'}}
Douglas Gregora119f102008-12-19 19:13:09 +0000101}
John McCall6d1116a2010-06-11 10:04:22 +0000102
103namespace test5 {
104 void foo(bool);
105 void foo(void *);
106
107 void test(id p) {
108 foo(p);
109 }
110}
John McCallf28e83a2010-10-26 06:23:29 +0000111
112// rdar://problem/8592139
113namespace test6 {
Douglas Gregor058d3de2011-01-31 18:51:41 +0000114 void foo(id); // expected-note{{candidate function}}
John McCallf28e83a2010-10-26 06:23:29 +0000115 void foo(A*) __attribute__((unavailable)); // expected-note {{explicitly made unavailable}}
116
117 void test(B *b) {
Douglas Gregor058d3de2011-01-31 18:51:41 +0000118 foo(b); // expected-error {{call to unavailable function 'foo'}}
John McCallf28e83a2010-10-26 06:23:29 +0000119 }
120}
Douglas Gregor8d6d0672010-12-01 21:43:58 +0000121
122namespace rdar8714395 {
123 int &f(const void*);
124 float &f(const Foo*);
125
126 int &f2(const void*);
127 float &f2(Foo const* const *);
128
129 int &f3(const void*);
130 float &f3(Foo const**);
131
132 void g(Foo *p) {
133 float &fr = f(p);
134 float &fr2 = f2(&p);
135 int &ir = f3(&p);
136 }
137
138
139}
Douglas Gregorc6bd1d32010-12-06 22:09:19 +0000140
141namespace rdar8734046 {
142 void f1(id);
143 void f2(id<P0>);
144 void g(const A *a) {
145 f1(a);
146 f2(a);
147 }
148}
Douglas Gregor5d3d3fa2011-04-15 20:45:44 +0000149
150namespace PR9735 {
151 int &f3(const A*);
152 float &f3(const void*);
153
154 void test_f(B* b, const B* bc) {
155 int &ir1 = f3(b);
156 int &ir2 = f3(bc);
157 }
158}
Douglas Gregor30ee16f2011-04-27 00:01:52 +0000159
160@interface D : B
161@end
162
163namespace rdar9327203 {
164 int &f(void* const&, int);
165 float &f(void* const&, long);
166
167 void g(id x) {
168 int &fr = (f)(x, 0);
169 }
170}
Douglas Gregor843e9782011-12-15 17:20:18 +0000171
172namespace class_id {
173 // it's okay to overload Class with id.
174 void f(Class) { }
175 void f(id) { }
176}