]>
git.proxmox.com Git - rustc.git/blob - src/llvm/tools/clang/test/SemaCXX/overloaded-builtin-operators.cpp
1 // RUN: %clang_cc1 -fsyntax-only -fshow-overloads=best -verify %s
30 typedef void (X::*pmf
)();
36 yes
& islong(unsigned long); // FIXME: shouldn't be needed
39 void f(Short s
, Long l
, Enum1 e1
, Enum2 e2
, Xpmf pmf
) {
44 // C++ [over.built]p10:
48 // C++ [over.built]p12
49 (void)static_cast<yes
&>(islong(s
+ l
));
50 (void)static_cast<no
&>(islong(s
+ s
));
52 // C++ [over.built]p16
56 // C++ [over.built]p17
57 (void)static_cast<yes
&>(islong(s
% l
));
58 (void)static_cast<yes
&>(islong(l
<< s
));
59 (void)static_cast<no
&>(islong(s
<< l
));
60 (void)static_cast<yes
&>(islong(e1
% l
));
61 // FIXME: should pass (void)static_cast<no&>(islong(e1 % e2));
64 struct ShortRef
{ // expected-note{{candidate function (the implicit copy assignment operator)}}
69 operator volatile long&();
72 struct XpmfRef
{ // expected-note{{candidate function (the implicit copy assignment operator)}}
80 void g(ShortRef sr
, LongRef lr
, E2Ref e2_ref
, XpmfRef pmf_ref
) {
87 // C++ [over.built]p18
88 short& sr1
= (sr
*= lr
);
89 volatile long& lr1
= (lr
*= sr
);
91 // C++ [over.built]p20:
95 pmf
&pmr
= (pmf_ref
= &X::f
); // expected-error{{no viable overloaded '='}}
99 // C++ [over.built]p22
100 short& sr2
= (sr
%= lr
);
101 volatile long& lr2
= (lr
<<= sr
);
103 bool b1
= (sr
&& lr
) || (sr
|| lr
);
106 struct VolatileIntPtr
{
107 operator int volatile *();
111 operator int const *();
114 struct VolatileIntPtrRef
{
115 operator int volatile *&();
118 struct ConstIntPtrRef
{
119 operator int const *&();
122 void test_with_ptrs(VolatileIntPtr vip
, ConstIntPtr cip
, ShortRef sr
,
123 VolatileIntPtrRef vipr
, ConstIntPtrRef cipr
) {
124 const int& cir1
= cip
[sr
];
125 const int& cir2
= sr
[cip
];
126 volatile int& vir1
= vip
[sr
];
127 volatile int& vir2
= sr
[vip
];
128 bool b1
= (vip
== cip
);
131 // C++ [over.built]p5:
132 int volatile *vip1
= vipr
++;
133 int const *cip1
= cipr
++;
134 int volatile *&vipr1
= ++vipr
;
135 int const *&cipr1
= --cipr
;
137 // C++ [over.built]p6:
138 int volatile &ivr
= *vip
;
140 // C++ [over.built]p8:
141 int volatile *vip2
= +vip
;
145 // C++ [over.built]p13:
146 int volatile &ivr2
= vip
[17];
147 int const &icr2
= 17[cip
];
150 // C++ [over.match.open]p4
152 void test_assign_restrictions(ShortRef
& sr
) {
153 sr
= (short)0; // expected-error{{no viable overloaded '='}}
157 struct Derived1
: Base
{ };
158 struct Derived2
: Base
{ };
161 struct ConvertibleToPtrOf
{
165 bool test_with_base_ptrs(ConvertibleToPtrOf
<Derived1
> d1
,
166 ConvertibleToPtrOf
<Derived2
> d2
) {
167 return d1
== d2
; // expected-error{{invalid operands}}
172 template< typename T
> operator T() const;
175 void test_dr425(A a
) {
176 // FIXME: lots of candidates here!
177 (void)(1.0f
* a
); // expected-error{{ambiguous}} \
178 // expected-note 4{{candidate}} \
179 // expected-note {{remaining 117 candidates omitted; pass -fshow-overloads=all to show them}}
185 const int a
[][2] = {{1}};
192 (void)__extension__(A());
196 typedef enum { Enum1
, Enum2
, Enum3
} MyEnum
;
198 template<typename X
> bool operator>(const X
&inX1
, const X
&inX2
);
209 operator const char *();
219 (void)(foo
- foo
); // expected-error{{use of overloaded operator '-' is ambiguous}} \
220 // expected-note 4{{built-in candidate operator-}} \
221 // expected-note{{candidates omitted}}
222 return foo
[zero
] == zero
;
228 operator const void *() const;
231 operator const unsigned *() const;
232 operator unsigned *();
251 operator int* __restrict
&();
254 void user_conversions(RestrictInt ri
) {
263 struct X
{ operator __int128() const; } x
;
264 bool a
= x
== __int128(0);
267 struct Y
{ operator unsigned __int128() const; } y
;
268 bool c
= y
== __int128(0);