Teach TreeTransform how to transform a pack expansion type into
[clang.git] / test / SemaObjCXX / overload.mm
blob750b6b183a8d027effe332abf0ca690d3dd8ca70
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 @interface Foo
3 @end
5 @implementation Foo
7 void func(id);
9 + zone {
10  func(self);
11  return self;
13 @end
15 @protocol P0
16 @end
18 @protocol P1
19 @end
21 @interface A <P0>
22 @end
24 @interface B : A
25 @end
27 @interface C <P1>
28 @end
30 int& f(A*); // expected-note {{candidate}}
31 float& f(B*); // expected-note {{candidate}}
32 void g(A*);
34 int& h(A*); // expected-note{{candidate}}
35 float& h(id); // expected-note{{candidate}}
37 void test0(A* a, B* b, id val) {
38   int& i1 = f(a);
39   float& f1 = f(b);
41   // GCC succeeds here, which is clearly ridiculous.
42   float& f2 = f(val); // expected-error {{ambiguous}}
44   g(a);
45   g(b);
46   g(val);
47   int& i2 = h(a);
48   float& f3 = h(val);
50   // FIXME: we match GCC here, but shouldn't this work?
51   int& i3 = h(b); // expected-error{{call to 'h' is ambiguous}}
54 void test1(A* a) {
55   B* b = a; // expected-warning{{incompatible pointer types initializing 'A *' with an expression of type 'B *'}}
56   B *c; c = a; // expected-warning{{incompatible pointer types assigning to 'A *' from 'B *'}}
59 void test2(A** ap) {
60   B** bp = ap; // expected-warning{{incompatible pointer types initializing 'A **' with an expression of type 'B **'}}
61   bp = ap; // expected-warning{{incompatible pointer types assigning to 'A **' from 'B **'}}
64 // FIXME: we should either allow overloading here or give a better diagnostic
65 int& cv(A*); // expected-note {{previous declaration}} expected-note 2 {{not viable}}
66 float& cv(const A*); // expected-error {{cannot be overloaded}}
68 int& cv2(void*);
69 float& cv2(const void*);
71 void cv_test(A* a, B* b, const A* ac, const B* bc) {
72   int &i1 = cv(a);
73   int &i2 = cv(b);
74   float &f1 = cv(ac); // expected-error {{no matching function}}
75   float &f2 = cv(bc); // expected-error {{no matching function}}
76   int& i3 = cv2(a);
77   float& f3 = cv2(ac);
80 // We agree with GCC that these can't be overloaded.
81 int& qualid(id<P0>); // expected-note {{previous declaration}} expected-note {{not viable}}
82 float& qualid(id<P1>); // expected-error {{cannot be overloaded}}
84 void qualid_test(A *a, B *b, C *c) {
85   int& i1 = qualid(a);
86   int& i2 = qualid(b);
88   // This doesn't work only because the overload was rejected above.
89   float& f1 = qualid(c); // expected-error {{no matching function}}
91   id<P0> p1 = 0;
92   p1 = 0;
96 @class NSException;
97 typedef struct {
98     void (*throw_exc)(id);
100 objc_exception_functions_t;
102 void (*_NSExceptionRaiser(void))(NSException *) {
103     objc_exception_functions_t exc_funcs;
104     return exc_funcs.throw_exc; // expected-warning{{incompatible pointer types returning 'void (*)(id)' from a function with result type 'void (*)(NSException *)'}}
107 namespace test5 {
108   void foo(bool);
109   void foo(void *);
111   void test(id p) {
112     foo(p);
113   }
116 // rdar://problem/8592139
117 // FIXME: this should resolve to the unavailable candidate
118 namespace test6 {
119   void foo(id); // expected-note {{candidate}}
120   void foo(A*) __attribute__((unavailable)); // expected-note {{explicitly made unavailable}}
122   void test(B *b) {
123     foo(b); // expected-error {{call to 'foo' is ambiguous}}
124   }
127 namespace rdar8714395 {
128   int &f(const void*);
129   float &f(const Foo*);
131   int &f2(const void*);
132   float &f2(Foo const* const *);
134   int &f3(const void*);
135   float &f3(Foo const**);
137   void g(Foo *p) {
138     float &fr = f(p);
139     float &fr2 = f2(&p);
140     int &ir = f3(&p);
141   }
143   
146 namespace rdar8734046 {
147   void f1(id);
148   void f2(id<P0>);
149   void g(const A *a) {
150     f1(a);
151     f2(a);
152   }