1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -fshow-overloads=best -verify -triple x86_64-linux-gnu %s
2*f4a2713aSLionel Sambuc
3*f4a2713aSLionel Sambuc struct yes;
4*f4a2713aSLionel Sambuc struct no;
5*f4a2713aSLionel Sambuc
6*f4a2713aSLionel Sambuc struct Short {
7*f4a2713aSLionel Sambuc operator short();
8*f4a2713aSLionel Sambuc };
9*f4a2713aSLionel Sambuc
10*f4a2713aSLionel Sambuc struct Long {
11*f4a2713aSLionel Sambuc operator long();
12*f4a2713aSLionel Sambuc };
13*f4a2713aSLionel Sambuc
14*f4a2713aSLionel Sambuc enum E1 { };
15*f4a2713aSLionel Sambuc struct Enum1 {
16*f4a2713aSLionel Sambuc operator E1();
17*f4a2713aSLionel Sambuc };
18*f4a2713aSLionel Sambuc
19*f4a2713aSLionel Sambuc enum E2 { };
20*f4a2713aSLionel Sambuc struct Enum2 {
21*f4a2713aSLionel Sambuc operator E2();
22*f4a2713aSLionel Sambuc };
23*f4a2713aSLionel Sambuc
24*f4a2713aSLionel Sambuc
25*f4a2713aSLionel Sambuc struct X {
26*f4a2713aSLionel Sambuc void f();
27*f4a2713aSLionel Sambuc };
28*f4a2713aSLionel Sambuc
29*f4a2713aSLionel Sambuc typedef void (X::*pmf)();
30*f4a2713aSLionel Sambuc struct Xpmf {
31*f4a2713aSLionel Sambuc operator pmf();
32*f4a2713aSLionel Sambuc };
33*f4a2713aSLionel Sambuc
34*f4a2713aSLionel Sambuc yes& islong(long);
35*f4a2713aSLionel Sambuc yes& islong(unsigned long); // FIXME: shouldn't be needed
36*f4a2713aSLionel Sambuc no& islong(int);
37*f4a2713aSLionel Sambuc
f(Short s,Long l,Enum1 e1,Enum2 e2,Xpmf pmf)38*f4a2713aSLionel Sambuc void f(Short s, Long l, Enum1 e1, Enum2 e2, Xpmf pmf) {
39*f4a2713aSLionel Sambuc // C++ [over.built]p8
40*f4a2713aSLionel Sambuc int i1 = +e1;
41*f4a2713aSLionel Sambuc int i2 = -e2;
42*f4a2713aSLionel Sambuc
43*f4a2713aSLionel Sambuc // C++ [over.built]p10:
44*f4a2713aSLionel Sambuc int i3 = ~s;
45*f4a2713aSLionel Sambuc bool b1 = !s;
46*f4a2713aSLionel Sambuc
47*f4a2713aSLionel Sambuc // C++ [over.built]p12
48*f4a2713aSLionel Sambuc (void)static_cast<yes&>(islong(s + l));
49*f4a2713aSLionel Sambuc (void)static_cast<no&>(islong(s + s));
50*f4a2713aSLionel Sambuc
51*f4a2713aSLionel Sambuc // C++ [over.built]p16
52*f4a2713aSLionel Sambuc (void)(pmf == &X::f);
53*f4a2713aSLionel Sambuc (void)(pmf == 0);
54*f4a2713aSLionel Sambuc
55*f4a2713aSLionel Sambuc // C++ [over.built]p17
56*f4a2713aSLionel Sambuc (void)static_cast<yes&>(islong(s % l));
57*f4a2713aSLionel Sambuc (void)static_cast<yes&>(islong(l << s));
58*f4a2713aSLionel Sambuc (void)static_cast<no&>(islong(s << l));
59*f4a2713aSLionel Sambuc (void)static_cast<yes&>(islong(e1 % l));
60*f4a2713aSLionel Sambuc // FIXME: should pass (void)static_cast<no&>(islong(e1 % e2));
61*f4a2713aSLionel Sambuc }
62*f4a2713aSLionel Sambuc
63*f4a2713aSLionel Sambuc struct ShortRef { // expected-note{{candidate function (the implicit copy assignment operator)}}
64*f4a2713aSLionel Sambuc operator short&();
65*f4a2713aSLionel Sambuc };
66*f4a2713aSLionel Sambuc
67*f4a2713aSLionel Sambuc struct LongRef {
68*f4a2713aSLionel Sambuc operator volatile long&();
69*f4a2713aSLionel Sambuc };
70*f4a2713aSLionel Sambuc
71*f4a2713aSLionel Sambuc struct XpmfRef { // expected-note{{candidate function (the implicit copy assignment operator)}}
72*f4a2713aSLionel Sambuc operator pmf&();
73*f4a2713aSLionel Sambuc };
74*f4a2713aSLionel Sambuc
75*f4a2713aSLionel Sambuc struct E2Ref {
76*f4a2713aSLionel Sambuc operator E2&();
77*f4a2713aSLionel Sambuc };
78*f4a2713aSLionel Sambuc
g(ShortRef sr,LongRef lr,E2Ref e2_ref,XpmfRef pmf_ref)79*f4a2713aSLionel Sambuc void g(ShortRef sr, LongRef lr, E2Ref e2_ref, XpmfRef pmf_ref) {
80*f4a2713aSLionel Sambuc // C++ [over.built]p3
81*f4a2713aSLionel Sambuc short s1 = sr++;
82*f4a2713aSLionel Sambuc
83*f4a2713aSLionel Sambuc // C++ [over.built]p3
84*f4a2713aSLionel Sambuc long l1 = lr--;
85*f4a2713aSLionel Sambuc
86*f4a2713aSLionel Sambuc // C++ [over.built]p18
87*f4a2713aSLionel Sambuc short& sr1 = (sr *= lr);
88*f4a2713aSLionel Sambuc volatile long& lr1 = (lr *= sr);
89*f4a2713aSLionel Sambuc
90*f4a2713aSLionel Sambuc // C++ [over.built]p20:
91*f4a2713aSLionel Sambuc E2 e2r2;
92*f4a2713aSLionel Sambuc e2r2 = e2_ref;
93*f4a2713aSLionel Sambuc
94*f4a2713aSLionel Sambuc pmf &pmr = (pmf_ref = &X::f); // expected-error{{no viable overloaded '='}}
95*f4a2713aSLionel Sambuc pmf pmr2;
96*f4a2713aSLionel Sambuc pmr2 = pmf_ref;
97*f4a2713aSLionel Sambuc
98*f4a2713aSLionel Sambuc // C++ [over.built]p22
99*f4a2713aSLionel Sambuc short& sr2 = (sr %= lr);
100*f4a2713aSLionel Sambuc volatile long& lr2 = (lr <<= sr);
101*f4a2713aSLionel Sambuc
102*f4a2713aSLionel Sambuc bool b1 = (sr && lr) || (sr || lr);
103*f4a2713aSLionel Sambuc }
104*f4a2713aSLionel Sambuc
105*f4a2713aSLionel Sambuc struct VolatileIntPtr {
106*f4a2713aSLionel Sambuc operator int volatile *();
107*f4a2713aSLionel Sambuc };
108*f4a2713aSLionel Sambuc
109*f4a2713aSLionel Sambuc struct ConstIntPtr {
110*f4a2713aSLionel Sambuc operator int const *();
111*f4a2713aSLionel Sambuc };
112*f4a2713aSLionel Sambuc
113*f4a2713aSLionel Sambuc struct VolatileIntPtrRef {
114*f4a2713aSLionel Sambuc operator int volatile *&();
115*f4a2713aSLionel Sambuc };
116*f4a2713aSLionel Sambuc
117*f4a2713aSLionel Sambuc struct ConstIntPtrRef {
118*f4a2713aSLionel Sambuc operator int const *&();
119*f4a2713aSLionel Sambuc };
120*f4a2713aSLionel Sambuc
test_with_ptrs(VolatileIntPtr vip,ConstIntPtr cip,ShortRef sr,VolatileIntPtrRef vipr,ConstIntPtrRef cipr)121*f4a2713aSLionel Sambuc void test_with_ptrs(VolatileIntPtr vip, ConstIntPtr cip, ShortRef sr,
122*f4a2713aSLionel Sambuc VolatileIntPtrRef vipr, ConstIntPtrRef cipr) {
123*f4a2713aSLionel Sambuc const int& cir1 = cip[sr];
124*f4a2713aSLionel Sambuc const int& cir2 = sr[cip];
125*f4a2713aSLionel Sambuc volatile int& vir1 = vip[sr];
126*f4a2713aSLionel Sambuc volatile int& vir2 = sr[vip];
127*f4a2713aSLionel Sambuc bool b1 = (vip == cip);
128*f4a2713aSLionel Sambuc long p1 = vip - cip;
129*f4a2713aSLionel Sambuc
130*f4a2713aSLionel Sambuc // C++ [over.built]p5:
131*f4a2713aSLionel Sambuc int volatile *vip1 = vipr++;
132*f4a2713aSLionel Sambuc int const *cip1 = cipr++;
133*f4a2713aSLionel Sambuc int volatile *&vipr1 = ++vipr;
134*f4a2713aSLionel Sambuc int const *&cipr1 = --cipr;
135*f4a2713aSLionel Sambuc
136*f4a2713aSLionel Sambuc // C++ [over.built]p6:
137*f4a2713aSLionel Sambuc int volatile &ivr = *vip;
138*f4a2713aSLionel Sambuc
139*f4a2713aSLionel Sambuc // C++ [over.built]p8:
140*f4a2713aSLionel Sambuc int volatile *vip2 = +vip;
141*f4a2713aSLionel Sambuc int i1 = +sr;
142*f4a2713aSLionel Sambuc int i2 = -sr;
143*f4a2713aSLionel Sambuc
144*f4a2713aSLionel Sambuc // C++ [over.built]p13:
145*f4a2713aSLionel Sambuc int volatile &ivr2 = vip[17];
146*f4a2713aSLionel Sambuc int const &icr2 = 17[cip];
147*f4a2713aSLionel Sambuc }
148*f4a2713aSLionel Sambuc
149*f4a2713aSLionel Sambuc // C++ [over.match.open]p4
150*f4a2713aSLionel Sambuc
test_assign_restrictions(ShortRef & sr)151*f4a2713aSLionel Sambuc void test_assign_restrictions(ShortRef& sr) {
152*f4a2713aSLionel Sambuc sr = (short)0; // expected-error{{no viable overloaded '='}}
153*f4a2713aSLionel Sambuc }
154*f4a2713aSLionel Sambuc
155*f4a2713aSLionel Sambuc struct Base { };
156*f4a2713aSLionel Sambuc struct Derived1 : Base { };
157*f4a2713aSLionel Sambuc struct Derived2 : Base { };
158*f4a2713aSLionel Sambuc
159*f4a2713aSLionel Sambuc template<typename T>
160*f4a2713aSLionel Sambuc struct ConvertibleToPtrOf {
161*f4a2713aSLionel Sambuc operator T*();
162*f4a2713aSLionel Sambuc };
163*f4a2713aSLionel Sambuc
test_with_base_ptrs(ConvertibleToPtrOf<Derived1> d1,ConvertibleToPtrOf<Derived2> d2)164*f4a2713aSLionel Sambuc bool test_with_base_ptrs(ConvertibleToPtrOf<Derived1> d1,
165*f4a2713aSLionel Sambuc ConvertibleToPtrOf<Derived2> d2) {
166*f4a2713aSLionel Sambuc return d1 == d2; // expected-error{{invalid operands}}
167*f4a2713aSLionel Sambuc }
168*f4a2713aSLionel Sambuc
169*f4a2713aSLionel Sambuc // DR425
170*f4a2713aSLionel Sambuc struct A {
171*f4a2713aSLionel Sambuc template< typename T > operator T() const;
172*f4a2713aSLionel Sambuc };
173*f4a2713aSLionel Sambuc
test_dr425(A a)174*f4a2713aSLionel Sambuc void test_dr425(A a) {
175*f4a2713aSLionel Sambuc // FIXME: lots of candidates here!
176*f4a2713aSLionel Sambuc (void)(1.0f * a); // expected-error{{ambiguous}} \
177*f4a2713aSLionel Sambuc // expected-note 4{{candidate}} \
178*f4a2713aSLionel Sambuc // expected-note {{remaining 117 candidates omitted; pass -fshow-overloads=all to show them}}
179*f4a2713aSLionel Sambuc }
180*f4a2713aSLionel Sambuc
181*f4a2713aSLionel Sambuc // pr5432
182*f4a2713aSLionel Sambuc enum e {X};
183*f4a2713aSLionel Sambuc
184*f4a2713aSLionel Sambuc const int a[][2] = {{1}};
185*f4a2713aSLionel Sambuc
test_pr5432()186*f4a2713aSLionel Sambuc int test_pr5432() {
187*f4a2713aSLionel Sambuc return a[X][X];
188*f4a2713aSLionel Sambuc }
189*f4a2713aSLionel Sambuc
f()190*f4a2713aSLionel Sambuc void f() {
191*f4a2713aSLionel Sambuc (void)__extension__(A());
192*f4a2713aSLionel Sambuc }
193*f4a2713aSLionel Sambuc
194*f4a2713aSLionel Sambuc namespace PR7319 {
195*f4a2713aSLionel Sambuc typedef enum { Enum1, Enum2, Enum3 } MyEnum;
196*f4a2713aSLionel Sambuc
197*f4a2713aSLionel Sambuc template<typename X> bool operator>(const X &inX1, const X &inX2);
198*f4a2713aSLionel Sambuc
f()199*f4a2713aSLionel Sambuc void f() {
200*f4a2713aSLionel Sambuc MyEnum e1, e2;
201*f4a2713aSLionel Sambuc if (e1 > e2) {}
202*f4a2713aSLionel Sambuc }
203*f4a2713aSLionel Sambuc }
204*f4a2713aSLionel Sambuc
205*f4a2713aSLionel Sambuc namespace PR8477 {
206*f4a2713aSLionel Sambuc struct Foo {
207*f4a2713aSLionel Sambuc operator bool();
208*f4a2713aSLionel Sambuc operator const char *();
209*f4a2713aSLionel Sambuc };
210*f4a2713aSLionel Sambuc
doit()211*f4a2713aSLionel Sambuc bool doit() {
212*f4a2713aSLionel Sambuc Foo foo;
213*f4a2713aSLionel Sambuc long long zero = 0;
214*f4a2713aSLionel Sambuc (void)(foo + zero);
215*f4a2713aSLionel Sambuc (void)(foo - zero);
216*f4a2713aSLionel Sambuc (void)(zero + foo);
217*f4a2713aSLionel Sambuc (void)(zero[foo]);
218*f4a2713aSLionel Sambuc (void)(foo - foo); // expected-error{{use of overloaded operator '-' is ambiguous}} \
219*f4a2713aSLionel Sambuc // expected-note 4{{built-in candidate operator-}} \
220*f4a2713aSLionel Sambuc // expected-note{{candidates omitted}}
221*f4a2713aSLionel Sambuc return foo[zero] == zero;
222*f4a2713aSLionel Sambuc }
223*f4a2713aSLionel Sambuc }
224*f4a2713aSLionel Sambuc
225*f4a2713aSLionel Sambuc namespace PR7851 {
226*f4a2713aSLionel Sambuc struct X {
227*f4a2713aSLionel Sambuc operator const void *() const;
228*f4a2713aSLionel Sambuc operator void *();
229*f4a2713aSLionel Sambuc
230*f4a2713aSLionel Sambuc operator const unsigned *() const;
231*f4a2713aSLionel Sambuc operator unsigned *();
232*f4a2713aSLionel Sambuc };
233*f4a2713aSLionel Sambuc
f()234*f4a2713aSLionel Sambuc void f() {
235*f4a2713aSLionel Sambuc X x;
236*f4a2713aSLionel Sambuc x[0] = 1;
237*f4a2713aSLionel Sambuc *x = 0;
238*f4a2713aSLionel Sambuc (void)(x - x);
239*f4a2713aSLionel Sambuc }
240*f4a2713aSLionel Sambuc }
241*f4a2713aSLionel Sambuc
242*f4a2713aSLionel Sambuc namespace PR12854 {
243*f4a2713aSLionel Sambuc enum { size = 1 };
plus_equals()244*f4a2713aSLionel Sambuc void plus_equals() {
245*f4a2713aSLionel Sambuc int* __restrict py;
246*f4a2713aSLionel Sambuc py += size;
247*f4a2713aSLionel Sambuc }
248*f4a2713aSLionel Sambuc
249*f4a2713aSLionel Sambuc struct RestrictInt {
250*f4a2713aSLionel Sambuc operator int* __restrict &();
251*f4a2713aSLionel Sambuc };
252*f4a2713aSLionel Sambuc
user_conversions(RestrictInt ri)253*f4a2713aSLionel Sambuc void user_conversions(RestrictInt ri) {
254*f4a2713aSLionel Sambuc ++ri;
255*f4a2713aSLionel Sambuc --ri;
256*f4a2713aSLionel Sambuc ri++;
257*f4a2713aSLionel Sambuc ri--;
258*f4a2713aSLionel Sambuc }
259*f4a2713aSLionel Sambuc }
260*f4a2713aSLionel Sambuc
261*f4a2713aSLionel Sambuc namespace PR12964 {
262*f4a2713aSLionel Sambuc struct X { operator __int128() const; } x;
263*f4a2713aSLionel Sambuc bool a = x == __int128(0);
264*f4a2713aSLionel Sambuc bool b = x == 0;
265*f4a2713aSLionel Sambuc
266*f4a2713aSLionel Sambuc struct Y { operator unsigned __int128() const; } y;
267*f4a2713aSLionel Sambuc bool c = y == __int128(0);
268*f4a2713aSLionel Sambuc bool d = y == 0;
269*f4a2713aSLionel Sambuc
270*f4a2713aSLionel Sambuc bool e = x == y;
271*f4a2713aSLionel Sambuc }
272