1 // RUN: %clang_cc1 -fsyntax-only -verify %s
22 bool operator-(Y
, Y
); // expected-note{{candidate function}}
23 bool operator-(Z
, Z
); // expected-note{{candidate function}}
27 bool b
= y
- z
; // expected-error{{use of overloaded operator '-' is ambiguous}}
31 bool operator==(Z
&); // expected-note 2{{candidate function}}
36 bool operator==(A
&, Z
&); // expected-note 2{{candidate function}}
38 void h(A a
, const A ac
, Z z
) {
40 a
== z
; // expected-error{{use of overloaded operator '==' is ambiguous}}
41 ac
== z
; // expected-error{{invalid operands to binary expression ('const A' and 'Z')}}
45 bool operator==(const B
&) const;
52 // we shouldn't see warnings about self-comparison,
53 // this is a member function, we dunno what it'll do
70 // C++ [over.match.oper]p3 - enum restriction.
71 float& operator==(E1
, E2
);
73 void enum_test(Enum1 enum1
, Enum2 enum2
, E1 e1
, E2 e2
) {
74 float &f1
= (e1
== e2
);
75 float &f2
= (enum1
== e2
);
76 float &f3
= (e1
== enum2
);
77 float &f4
= (enum1
== enum2
); // expected-error{{non-const lvalue reference to type 'float' cannot bind to a temporary of type 'bool'}}
80 // PR5244 - Argument-dependent lookup would include the two operators below,
81 // which would break later assumptions and lead to a crash.
88 bool operator==(const pr5244_foo
& s1
, const pr5244_foo
& s2
);
89 bool operator==(char c
, const pr5244_foo
& s
);
105 (void)(pr5244_BAR
== quuux
.quux
);
111 PostInc
operator++(int);
112 PostInc
& operator++();
116 PostDec
operator--(int);
117 PostDec
& operator--();
120 void incdec_test(PostInc pi
, PostDec pd
) {
121 const PostInc
& pi1
= pi
++;
122 const PostDec
& pd1
= pd
--;
129 long& operator*() const volatile;
132 void test_smartptr(SmartPtr ptr
, const SmartPtr cptr
,
133 const volatile SmartPtr cvptr
) {
141 int& operator[](int);
144 void test_arraylike(ArrayLike a
) {
152 void test_smartref(SmartRef r
) {
156 bool& operator,(X
, Y
);
158 void test_comma(X x
, Y y
) {
160 X
& xr
= (x
, x
); // expected-warning {{expression result unused}}
164 int& operator()(int, double = 2.71828); // expected-note{{candidate function}}
165 float& operator()(int, double, long, ...); // expected-note{{candidate function}}
167 double& operator()(float); // expected-note{{candidate function}}
171 int& operator()(int i
= 0);
172 double& operator()(...) const;
175 struct DerivesCallable
: public Callable
{
178 void test_callable(Callable c
, Callable2 c2
, const Callable2
& c2c
,
179 DerivesCallable dc
) {
181 float &fr
= c(1, 3.14159, 17, 42);
183 c(); // expected-error{{no matching function for call to object of type 'Callable'}}
185 double &dr
= c(1.0f
);
192 double &fr3
= dc(3.14159f
);
197 typedef INTREF
Func1(FLOAT
, double);
198 typedef float& Func2(int, double);
200 struct ConvertToFunc
{
201 operator Func1
*(); // expected-note 2{{conversion candidate of type 'INTREF (*)(FLOAT, double)'}}
202 operator Func2
&(); // expected-note 2{{conversion candidate of type 'float &(&)(int, double)'}}
206 struct ConvertToFuncDerived
: ConvertToFunc
{ };
208 void test_funcptr_call(ConvertToFunc ctf
, ConvertToFuncDerived ctfd
) {
209 int &i1
= ctf(1.0f
, 2.0);
210 float &f1
= ctf((short int)1, 1.0f
);
211 ctf((long int)17, 2.0); // expected-error{{call to object of type 'ConvertToFunc' is ambiguous}}
214 int &i2
= ctfd(1.0f
, 2.0);
215 float &f2
= ctfd((short int)1, 1.0f
);
216 ctfd((long int)17, 2.0); // expected-error{{call to object of type 'ConvertToFuncDerived' is ambiguous}}
225 HasMember
* operator->();
229 Arrow1
operator->(); // expected-note{{candidate function}}
232 void test_arrow(Arrow1 a1
, Arrow2 a2
, const Arrow2 a3
) {
235 a3
->m
; // expected-error{{no viable overloaded 'operator->'; candidate is}}
241 struct CopyCon
: public CopyConBase
{
242 CopyCon(const CopyConBase
&Base
);
244 CopyCon(const CopyConBase
*Base
) {
254 N::X
operator+(N::X
, N::X
);
258 void test_X(N::X x
) {
263 struct AA
{ bool operator!=(AA
&); };
265 bool x(BB y
, BB z
) { return y
!= z
; }
269 AX
& operator ->(); // expected-note {{declared here}}
275 a
->b
= 0; // expected-error {{circular pointer delegation detected}}
279 struct CircB
& operator->(); // expected-note {{declared here}}
283 struct CircC
& operator->(); // expected-note {{declared here}}
286 struct CircA
& operator->(); // expected-note {{declared here}}
291 a
->val
= 0; // expected-error {{circular pointer delegation detected}}
294 // PR5360: Arrays should lead to built-in candidates for subscript.
299 int getPriority(Register r
) {
302 int usepri
[LastReg
+ 1];
305 // PR5546: Don't generate incorrect and ambiguous overloads for multi-level
310 extern const char *const sMoveCommands
[][2][2];
311 const char* a() { return sMoveCommands
[X
][0][0]; }
312 const char* b() { return (*(sMoveCommands
+X
))[0][0]; }
315 // PR5512 and its discussion
323 // DR507, this should be ambiguous, but we special-case assignment
325 // Note: DR507, this is ambiguous as specified
330 void operator +=(int&, S
);
336 struct A
{operator int();};
345 struct NotAnArray
{};
348 x
[0] = 0; // expected-error {{does not provide a subscript operator}}
351 struct NonConstArray
{
352 int operator[](unsigned); // expected-note {{candidate}}
355 const NonConstArray x
= NonConstArray();
356 return x
[0]; // expected-error {{no viable overloaded operator[] for type}}
359 // Not really part of this PR, but implemented at the same time.
360 struct NotAFunction
{};
363 x(); // expected-error {{does not provide a call operator}}
367 // Operator lookup through using declarations.
376 N::X2
&operator<<(N::X2
&, const T
&);
378 using Inner::operator<<;
382 void test_lookup_through_using() {
383 using namespace N2::M
;