blob: f8c917cf2abddb43e462b56cce6e3647e5728374 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -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
John McCall6d09da02010-10-26 06:23:29 +000030int& f(A*); // expected-note {{candidate}}
31float& f(B*); // expected-note {{candidate}}
Douglas Gregorcb7de522008-11-26 23:31:11 +000032void g(A*);
33
34int& h(A*);
35float& h(id);
36
John McCall6d09da02010-10-26 06:23:29 +000037void test0(A* a, B* b, id val) {
Douglas Gregorcb7de522008-11-26 23:31:11 +000038 int& i1 = f(a);
39 float& f1 = f(b);
John McCall6d09da02010-10-26 06:23:29 +000040
41 // GCC succeeds here, which is clearly ridiculous.
42 float& f2 = f(val); // expected-error {{ambiguous}}
43
Douglas Gregorcb7de522008-11-26 23:31:11 +000044 g(a);
45 g(b);
46 g(val);
47 int& i2 = h(a);
48 float& f3 = h(val);
49 // int& i3 = h(b); FIXME: we match GCC here, but shouldn't this work?
50}
51
John McCall6d09da02010-10-26 06:23:29 +000052// We make these errors instead of warnings. Is that okay?
53void test1(A* a) {
54 B* b = a; // expected-error{{cannot initialize a variable of type 'B *' with an lvalue of type 'A *'}}
55 B *c; c = a; // expected-error{{assigning to 'B *' from incompatible type 'A *'}}
Douglas Gregor45920e82008-12-19 17:40:08 +000056}
57
John McCall6d09da02010-10-26 06:23:29 +000058void test2(A** ap) {
59 B** bp = ap; // expected-warning{{incompatible pointer types converting 'A **' to type 'B **'}}
60 bp = ap; // expected-warning{{incompatible pointer types assigning to 'A **' from 'B **'}}
61}
62
63// FIXME: we should either allow overloading here or give a better diagnostic
64int& cv(A*); // expected-note {{previous declaration}} expected-note 2 {{not viable}}
65float& cv(const A*); // expected-error {{cannot be overloaded}}
66
67int& cv2(void*); // expected-note 2 {{candidate}}
68float& cv2(const void*); // expected-note 2 {{candidate}}
Douglas Gregorcb7de522008-11-26 23:31:11 +000069
70void cv_test(A* a, B* b, const A* ac, const B* bc) {
71 int &i1 = cv(a);
72 int &i2 = cv(b);
John McCall6d09da02010-10-26 06:23:29 +000073 float &f1 = cv(ac); // expected-error {{no matching function}}
74 float &f2 = cv(bc); // expected-error {{no matching function}}
75
76 // FIXME: these should not be ambiguous
77 int& i3 = cv2(a); // expected-error {{ambiguous}}
78 float& f3 = cv2(ac); // expected-error {{ambiguous}}
Douglas Gregorcb7de522008-11-26 23:31:11 +000079}
Douglas Gregor7ca09762008-11-27 01:19:21 +000080
John McCall6d09da02010-10-26 06:23:29 +000081// We agree with GCC that these can't be overloaded.
82int& qualid(id<P0>); // expected-note {{previous declaration}} expected-note {{not viable}}
83float& qualid(id<P1>); // expected-error {{cannot be overloaded}}
Douglas Gregor7ca09762008-11-27 01:19:21 +000084
85void qualid_test(A *a, B *b, C *c) {
86 int& i1 = qualid(a);
87 int& i2 = qualid(b);
John McCall6d09da02010-10-26 06:23:29 +000088
89 // This doesn't work only because the overload was rejected above.
90 float& f1 = qualid(c); // expected-error {{no matching function}}
Douglas Gregor27b09ac2008-12-22 20:51:52 +000091
92 id<P0> p1 = 0;
93 p1 = 0;
Douglas Gregor7ca09762008-11-27 01:19:21 +000094}
Douglas Gregorc7887512008-12-19 19:13:09 +000095
96
97@class NSException;
98typedef struct {
99 void (*throw_exc)(id);
100}
101objc_exception_functions_t;
102
103void (*_NSExceptionRaiser(void))(NSException *) {
104 objc_exception_functions_t exc_funcs;
John McCall6d09da02010-10-26 06:23:29 +0000105 return exc_funcs.throw_exc; // expected-warning{{incompatible pointer types converting 'void (*)(id)' to type 'void (*)(NSException *)'}}
Douglas Gregorc7887512008-12-19 19:13:09 +0000106}
John McCallddb0ce72010-06-11 10:04:22 +0000107
108namespace test5 {
109 void foo(bool);
110 void foo(void *);
111
112 void test(id p) {
113 foo(p);
114 }
115}
John McCall6d09da02010-10-26 06:23:29 +0000116
117// rdar://problem/8592139
118namespace test6 {
119 void foo(id); // expected-note {{candidate}}
120 void foo(A*) __attribute__((unavailable)); // expected-note {{explicitly made unavailable}}
121
122 void test(B *b) {
123 foo(b); // expected-error {{call to unavailable function}}
124 }
125}