blob: 7000e54cfe007ebdd116445477b625e343559d1e [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
Douglas Gregorda80f742010-12-01 21:43:58 +000034int& h(A*); // expected-note{{candidate}}
35float& h(id); // expected-note{{candidate}}
Douglas Gregorcb7de522008-11-26 23:31:11 +000036
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);
Douglas Gregorda80f742010-12-01 21:43:58 +000049
50 // FIXME: we match GCC here, but shouldn't this work?
51 int& i3 = h(b); // expected-error{{call to 'h' is ambiguous}}
Douglas Gregorcb7de522008-11-26 23:31:11 +000052}
53
John McCall6d09da02010-10-26 06:23:29 +000054void test1(A* a) {
Douglas Gregora3998bd2010-12-02 21:47:04 +000055 B* b = a; // expected-warning{{incompatible pointer types initializing 'A *' with an expression of type 'B *'}}
Douglas Gregorda80f742010-12-01 21:43:58 +000056 B *c; c = a; // expected-warning{{incompatible pointer types assigning to 'A *' from 'B *'}}
Douglas Gregor45920e82008-12-19 17:40:08 +000057}
58
John McCall6d09da02010-10-26 06:23:29 +000059void test2(A** ap) {
Douglas Gregora3998bd2010-12-02 21:47:04 +000060 B** bp = ap; // expected-warning{{incompatible pointer types initializing 'A **' with an expression of type 'B **'}}
John McCall6d09da02010-10-26 06:23:29 +000061 bp = ap; // expected-warning{{incompatible pointer types assigning to 'A **' from 'B **'}}
62}
63
64// FIXME: we should either allow overloading here or give a better diagnostic
65int& cv(A*); // expected-note {{previous declaration}} expected-note 2 {{not viable}}
66float& cv(const A*); // expected-error {{cannot be overloaded}}
67
Douglas Gregorda80f742010-12-01 21:43:58 +000068int& cv2(void*);
69float& cv2(const void*);
Douglas Gregorcb7de522008-11-26 23:31:11 +000070
71void cv_test(A* a, B* b, const A* ac, const B* bc) {
72 int &i1 = cv(a);
73 int &i2 = cv(b);
John McCall6d09da02010-10-26 06:23:29 +000074 float &f1 = cv(ac); // expected-error {{no matching function}}
75 float &f2 = cv(bc); // expected-error {{no matching function}}
Douglas Gregorda80f742010-12-01 21:43:58 +000076 int& i3 = cv2(a);
77 float& f3 = cv2(ac);
Douglas Gregorcb7de522008-11-26 23:31:11 +000078}
Douglas Gregor7ca09762008-11-27 01:19:21 +000079
John McCall6d09da02010-10-26 06:23:29 +000080// We agree with GCC that these can't be overloaded.
81int& qualid(id<P0>); // expected-note {{previous declaration}} expected-note {{not viable}}
82float& qualid(id<P1>); // expected-error {{cannot be overloaded}}
Douglas Gregor7ca09762008-11-27 01:19:21 +000083
84void qualid_test(A *a, B *b, C *c) {
85 int& i1 = qualid(a);
86 int& i2 = qualid(b);
John McCall6d09da02010-10-26 06:23:29 +000087
88 // This doesn't work only because the overload was rejected above.
89 float& f1 = qualid(c); // expected-error {{no matching function}}
Douglas Gregor27b09ac2008-12-22 20:51:52 +000090
91 id<P0> p1 = 0;
92 p1 = 0;
Douglas Gregor7ca09762008-11-27 01:19:21 +000093}
Douglas Gregorc7887512008-12-19 19:13:09 +000094
95
96@class NSException;
97typedef struct {
98 void (*throw_exc)(id);
99}
100objc_exception_functions_t;
101
102void (*_NSExceptionRaiser(void))(NSException *) {
103 objc_exception_functions_t exc_funcs;
Douglas Gregora3998bd2010-12-02 21:47:04 +0000104 return exc_funcs.throw_exc; // expected-warning{{incompatible pointer types returning 'void (*)(id)' from a function with result type 'void (*)(NSException *)'}}
Douglas Gregorc7887512008-12-19 19:13:09 +0000105}
John McCallddb0ce72010-06-11 10:04:22 +0000106
107namespace test5 {
108 void foo(bool);
109 void foo(void *);
110
111 void test(id p) {
112 foo(p);
113 }
114}
John McCall6d09da02010-10-26 06:23:29 +0000115
116// rdar://problem/8592139
John McCalldbfd0452010-10-26 06:41:10 +0000117// FIXME: this should resolve to the unavailable candidate
John McCall6d09da02010-10-26 06:23:29 +0000118namespace 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) {
John McCall202422e2010-10-26 06:40:27 +0000123 foo(b); // expected-error {{call to 'foo' is ambiguous}}
John McCall6d09da02010-10-26 06:23:29 +0000124 }
125}
Douglas Gregorda80f742010-12-01 21:43:58 +0000126
127namespace rdar8714395 {
128 int &f(const void*);
129 float &f(const Foo*);
130
131 int &f2(const void*);
132 float &f2(Foo const* const *);
133
134 int &f3(const void*);
135 float &f3(Foo const**);
136
137 void g(Foo *p) {
138 float &fr = f(p);
139 float &fr2 = f2(&p);
140 int &ir = f3(&p);
141 }
142
143
144}