1 // RUN: %clang_cc1 -fsyntax-only -verify=expected,precxx23 -std=c++11 %s
2 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx23 -std=c++23 %s
24 bool operator-(Y
, Y
); // expected-note{{candidate function}}
25 bool operator-(Z
, Z
); // expected-note{{candidate function}}
29 bool b
= y
- z
; // expected-error{{use of overloaded operator '-' is ambiguous}}
33 bool operator==(Z
&); // expected-note 2{{candidate function}}
38 bool operator==(A
&, Z
&); // expected-note 3{{candidate function}} \
39 // cxx23-note 2{{candidate function}}
42 void h(A a
, const A ac
, Z z
) {
43 make_A() == z
; // expected-warning{{equality comparison result unused}}
44 a
== z
; // expected-error{{use of overloaded operator '==' is ambiguous}}
45 ac
== z
; // expected-error{{invalid operands to binary expression ('const A' and 'Z')}}
49 bool operator==(const B
&) const;
52 make_A() == z
; // expected-warning{{equality comparison result unused}}
56 // we shouldn't see warnings about self-comparison,
57 // this is a member function, we dunno what it'll do
74 // C++ [over.match.oper]p3 - enum restriction.
75 float& operator==(E1
, E2
); // expected-note{{candidate function}} \
76 // cxx23-note{{candidate function}}
79 void enum_test(Enum1 enum1
, Enum2 enum2
, E1 e1
, E2 e2
, Enum1 next_enum1
) {
80 float &f1
= (e1
== e2
);
81 float &f2
= (enum1
== e2
);
82 float &f3
= (e1
== enum2
);
83 float &f4
= (enum1
== next_enum1
); // expected-error{{non-const lvalue reference to type 'float' cannot bind to a temporary of type 'bool'}}
86 // PR5244 - Argument-dependent lookup would include the two operators below,
87 // which would break later assumptions and lead to a crash.
94 bool operator==(const pr5244_foo
& s1
, const pr5244_foo
& s2
); // expected-note{{candidate function}}
95 bool operator==(char c
, const pr5244_foo
& s
); // expected-note{{candidate function}} \
96 // cxx23-note{{candidate function}}
112 (void)(pr5244_BAR
== quuux
.quux
);
118 PostInc
operator++(int);
119 PostInc
& operator++();
123 PostDec
operator--(int);
124 PostDec
& operator--();
127 void incdec_test(PostInc pi
, PostDec pd
) {
128 const PostInc
& pi1
= pi
++;
129 const PostDec
& pd1
= pd
--;
136 long& operator*() const volatile;
139 void test_smartptr(SmartPtr ptr
, const SmartPtr cptr
,
140 const volatile SmartPtr cvptr
) { // cxx23-warning {{volatile-qualified parameter type 'const volatile SmartPtr' is deprecated}}
148 int& operator[](int);
151 void test_arraylike(ArrayLike a
) {
159 void test_smartref(SmartRef r
) {
163 bool& operator,(X
, Y
);
165 void test_comma(X x
, Y y
) {
167 X
& xr
= (x
, x
); // expected-warning {{left operand of comma operator has no effect}}
171 int& operator()(int, double = 2.71828); // expected-note{{candidate function}}
172 float& operator()(int, double, long, ...); // expected-note{{candidate function}}
174 double& operator()(float); // expected-note{{candidate function}}
178 int& operator()(int i
= 0);
179 double& operator()(...) const;
182 struct DerivesCallable
: public Callable
{
185 void test_callable(Callable c
, Callable2 c2
, const Callable2
& c2c
,
186 DerivesCallable dc
) {
188 float &fr
= c(1, 3.14159, 17, 42);
190 c(); // expected-error{{no matching function for call to object of type 'Callable'}}
192 double &dr
= c(1.0f
);
199 double &fr3
= dc(3.14159f
);
204 typedef INTREF
Func1(FLOAT
, double);
205 typedef float& Func2(int, double);
207 struct ConvertToFunc
{
208 operator Func1
*(); // expected-note 2{{conversion candidate of type 'INTREF (*)(FLOAT, double)'}}
209 operator Func2
&(); // expected-note 2{{conversion candidate of type 'float &(&)(int, double)'}}
213 struct ConvertToFuncDerived
: ConvertToFunc
{ };
215 void test_funcptr_call(ConvertToFunc ctf
, ConvertToFuncDerived ctfd
) {
216 int &i1
= ctf(1.0f
, 2.0);
217 float &f1
= ctf((short int)1, 1.0f
);
218 ctf((long int)17, 2.0); // expected-error{{call to object of type 'ConvertToFunc' is ambiguous}}
221 int &i2
= ctfd(1.0f
, 2.0);
222 float &f2
= ctfd((short int)1, 1.0f
);
223 ctfd((long int)17, 2.0); // expected-error{{call to object of type 'ConvertToFuncDerived' is ambiguous}}
232 HasMember
* operator->();
236 Arrow1
operator->(); // expected-note{{candidate function}}
239 void test_arrow(Arrow1 a1
, Arrow2 a2
, const Arrow2 a3
) {
242 a3
->m
; // expected-error{{no viable overloaded 'operator->'}}
248 struct CopyCon
: public CopyConBase
{
249 CopyCon(const CopyConBase
&Base
);
251 CopyCon(const CopyConBase
*Base
) {
261 N::X
operator+(N::X
, N::X
);
265 void test_X(N::X x
) {
270 struct AA
{ bool operator!=(AA
&); };
272 bool x(BB y
, BB z
) { return y
!= z
; }
276 AX
& operator ->(); // expected-note {{declared here}}
282 a
->b
= 0; // expected-error {{circular pointer delegation detected}}
286 struct CircB
& operator->(); // expected-note {{declared here}}
290 struct CircC
& operator->(); // expected-note {{declared here}}
293 struct CircA
& operator->(); // expected-note {{declared here}}
298 a
->val
= 0; // expected-error {{circular pointer delegation detected}}
301 // PR5360: Arrays should lead to built-in candidates for subscript.
306 int getPriority(Register r
) {
309 int usepri
[LastReg
+ 1];
312 // PR5546: Don't generate incorrect and ambiguous overloads for multi-level
317 extern const char *const sMoveCommands
[][2][2];
318 const char* a() { return sMoveCommands
[X
][0][0]; }
319 const char* b() { return (*(sMoveCommands
+X
))[0][0]; }
322 // PR5512 and its discussion
330 // DR507, this should be ambiguous, but we special-case assignment
332 // Note: DR507, this is ambiguous as specified
337 void operator +=(int&, S
);
343 struct A
{operator int();};
352 struct NotAnArray
{};
355 x
[0] = 0; // expected-error {{does not provide a subscript operator}}
358 struct NonConstArray
{
359 int operator[](unsigned); // expected-note {{candidate}}
362 const NonConstArray x
= NonConstArray();
363 return x
[0]; // expected-error {{no viable overloaded operator[] for type}}
366 // Not really part of this PR, but implemented at the same time.
367 struct NotAFunction
{};
370 x(); // expected-error {{does not provide a call operator}}
374 // Operator lookup through using declarations.
383 N::X2
&operator<<(N::X2
&, const T
&);
385 using Inner::operator<<;
389 void test_lookup_through_using() {
390 using namespace N2::M
;
395 namespace rdar9136502
{
397 int i(); // expected-note{{possible target for call}}
398 int i(int); // expected-note{{possible target for call}}
407 .i
; // expected-error{{reference to non-static member function must be called; did you mean to call it with no arguments?}}
411 namespace rdar9222009
{
413 inline bool operator==(StringRef LHS
, StringRef RHS
) { // expected-error{{overloaded 'operator==' must be a binary operator (has 3 parameters)}}
414 return !(LHS
== RHS
); // expected-error{{invalid operands to binary expression ('StringRef' and 'StringRef')}}
421 struct A
{ A
& operator=(void (*x
)()); };
424 void g() { A x
; x
= f
; }
429 void operator[](float (*fn
)(int)); // expected-note 2 {{not viable: no overload of 'bar' matching 'float (*)(int)'}}
435 template <class T
> T
bar(T
);
436 template <class T
, class U
> T
bar(U
);
442 a
[&bar
<int>]; // expected-error {{no viable overloaded operator[]}}
443 a
[bar
<int>]; // expected-error {{no viable overloaded operator[]}}
445 // If these fail, it's because we're not letting the overload
446 // resolution for operator| resolve the overload of 'bar'.
452 struct InvalidOperatorEquals
{
453 InvalidOperatorEquals
operator=() = delete; // expected-error {{overloaded 'operator=' must be a binary operator}}
457 template <typename PT1
, typename PT2
> class PointerUnion
;
458 void foo(PointerUnion
<int*, float*> &Result
) {
459 Result
= 1; // expected-error {{no viable overloaded '='}} // expected-note {{type 'PointerUnion<int *, float *>' is incomplete}}
465 template<typename
...T
> void operator++(B
, T
...) {}
473 template<typename
... T
>
475 void operator-- (T
...) {}
486 template<typename T
> void operator++(D
, T
) {}
491 ++d
; // expected-error{{cannot increment value of type 'D'}}
494 template<typename
...T
> struct E
{
495 void operator++(T
...) {} // expected-error{{parameter of overloaded post-increment operator must have type 'int' (not 'char')}}
498 E
<char> e
; // expected-note {{in instantiation of template class 'PR14995::E<char>' requested here}}
501 template<typename
... T
>
502 int operator++ (T
...) {}
505 int k1
= F().operator++(0, 0);
506 int k2
= F().operator++('0');
507 // expected-error@-5 {{overloaded 'operator++' must be a unary or binary operator}}
508 // expected-note@-3 {{in instantiation of function template specialization 'PR14995::F::operator++<int, int>' requested here}}
509 // expected-error@-4 {{no matching member function for call to 'operator++'}}
510 // expected-note@-8 {{candidate template ignored: substitution failure}}
511 // expected-error@-9 {{parameter of overloaded post-increment operator must have type 'int' (not 'char')}}
512 // expected-note@-6 {{in instantiation of function template specialization 'PR14995::F::operator++<char>' requested here}}
513 // expected-error@-7 {{no matching member function for call to 'operator++'}}
514 // expected-note@-12 {{candidate template ignored: substitution failure}}
515 } // namespace PR14995
517 namespace ConversionVersusTemplateOrdering
{
519 operator short() = delete;
520 template <typename T
> operator T();
523 template <typename T
> operator T();
524 operator short() = delete;
530 namespace NoADLForMemberOnlyOperators
{
531 template<typename T
> struct A
{ typename
T::error e
; }; // expected-error {{type 'char' cannot be used prior to '::'}}
532 template<typename T
> struct B
{ int n
; };
534 void f(B
<A
<void> > b1
, B
<A
<int> > b2
, B
<A
<char> > b3
) {
535 b1
= b1
; // ok, does not instantiate A<void>.
536 (void)b1
->n
; // expected-error {{is not a pointer}}
537 b2
[3]; // expected-error {{does not provide a subscript}}
538 b3
/ 0; // expected-note {{in instantiation of}} expected-error {{invalid operands to}}
544 template <class T
> void operator+(T
, T
) = delete; // expected-note 4 {{candidate}}
545 template <class T
> void operator+(T
) = delete; // expected-note 4 {{candidate}}
547 struct A
{} a_global
;
550 +a
; // expected-error {{overload resolution selected deleted operator '+'}}
551 a
+ a
; // expected-error {{overload resolution selected deleted operator '+'}}
553 extern bool operator+(A
, A
);
557 bool test_global_1
= +a_global
; // expected-error {{overload resolution selected deleted operator '+'}}
558 bool test_global_2
= a_global
+ a_global
; // expected-error {{overload resolution selected deleted operator '+'}}
561 namespace LateADLInNonDependentExpressions
{
564 int &operator+(A
, A
);
566 int &operator+=(A
, A
);
567 int &operator<<(A
, A
);
569 int &operator++(A
, int);
570 int &operator->*(A
, A
);
572 template<typename T
> void f() {
573 // An instantiation-dependent value of type B.
574 // These are all non-dependent operator calls of type int&.
575 #define idB ((void()), B())
585 // These should not be found by ADL in the template instantiation.
586 float &operator+(B
, B
);
588 float &operator+=(B
, B
);
589 float &operator<<(B
, B
);
590 float &operator++(B
);
591 float &operator++(B
, int);
592 float &operator->*(B
, B
);
593 template void f
<int>();
598 template<typename T
> T
f(T t
) {
606 void g(B::X x
) { A::f(x
); }
613 void operator--() = delete; // expected-note {{candidate function has been explicitly deleted}} \
614 // expected-note {{candidate function not viable: requires 0 arguments, but 1 was provided}}
615 void operator--(int) = delete; // expected-note {{candidate function has been explicitly deleted}} \
616 // expected-note {{candidate function not viable: requires 1 argument, but 0 were provided}}
620 void operator--(this c
) = delete; //precxx23-error {{explicit object parameters are incompatible with C++ standards before C++2b}} \
621 // expected-note {{candidate function has been explicitly deleted}} \
622 // expected-note {{candidate function not viable: requires 0 non-object arguments, but 1 was provided}}
623 void operator--(this c
, int) = delete; //precxx23-error {{explicit object parameters are incompatible with C++ standards before C++2b}} \
624 // expected-note {{candidate function has been explicitly deleted}} \
625 // expected-note {{candidate function not viable: requires 1 non-object argument, but 0 were provided}}
630 --aa
; // expected-error {{overload resolution selected deleted operator '--'}}
631 aa
--; // expected-error {{overload resolution selected deleted operator '--'}}
634 --cc
; // expected-error {{overload resolution selected deleted operator '--'}}
635 cc
--; // expected-error {{overload resolution selected deleted operator '--'}}
639 void operator++() = delete; // expected-note {{candidate function has been explicitly deleted}}
640 template <class> void operator++(int) { // expected-note {{function template not viable: requires 1 argument, but 0 were provided}}
642 ++bb
; // expected-error {{overload resolution selected deleted operator '++'}}
649 #if __cplusplus >= 202002L
652 concept AlwaysTrue
=true;
656 void operator+(const T
&)const{}
658 template<AlwaysTrue T
>
659 int operator-(const T
&)const{return 0;}
661 template<AlwaysTrue T
>
662 int operator*(const T
&)const{ // expected-note {{candidate function}}
667 template<AlwaysTrue T
>
668 int operator+(const S
&, const T
&){return 0;}
671 void operator-(const S
&, const T
&){}
673 template<AlwaysTrue T
>
674 int operator*(const S
&, const T
&){ // expected-note {{candidate function}}
681 int c
= S
{} * 1; // expected-error {{use of overloaded operator '*' is ambiguous (with operand types 'S' and 'int')}}
686 #if __cplusplus >= 201703L
689 template <auto T
> struct A
{};
690 template <auto T
> A
<*T
> operator *() { return {}; }
691 // expected-error@-1 {{overloaded 'operator*' must have at least one parameter of class or enumeration type}}
700 auto operator *(constant
<x
>)
701 { return constant
<(*x
)>{}; }