blob: 1eb86bd1aa002147746a4fe6d347b8e813c6fe7f [file] [log] [blame]
Douglas Gregoreaebc752008-11-06 23:29:22 +00001// RUN: clang -fsyntax-only -verify %s
2class X { };
3
4X operator+(X, X);
5
6void f(X x) {
7 x = x + x;
8}
9
10struct Y;
11struct Z;
12
13struct Y {
14 Y(const Z&);
15};
16
17struct Z {
18 Z(const Y&);
19};
20
21Y operator+(Y, Y);
22bool operator-(Y, Y); // expected-note{{candidate function}}
23bool operator-(Z, Z); // expected-note{{candidate function}}
24
25void g(Y y, Z z) {
26 y = y + z;
27 bool b = y - z; // expected-error{{use of overloaded operator '-' is ambiguous; candidates are:}}
28}
29
Douglas Gregor96176b32008-11-18 23:14:02 +000030struct A {
31 bool operator==(Z&); // expected-note{{candidate function}}
32};
Douglas Gregoreaebc752008-11-06 23:29:22 +000033
Douglas Gregor96176b32008-11-18 23:14:02 +000034A make_A();
35
36bool operator==(A&, Z&); // expected-note{{candidate function}}
37
38void h(A a, const A ac, Z z) {
39 make_A() == z;
40 a == z; // expected-error{{use of overloaded operator '==' is ambiguous; candidates are:}}
41 ac == z; // expected-error{{invalid operands to binary expression ('struct A const' and 'struct Z')}}
42}
43
44struct B {
45 bool operator==(const B&) const;
46
47 void test(Z z) {
48 make_A() == z;
49 }
50};
Douglas Gregor447b69e2008-11-19 03:25:36 +000051
52enum Enum1 { };
53enum Enum2 { };
54
55struct E1 {
56 E1(Enum1) { }
57};
58
59struct E2 {
60 E2(Enum2);
61};
62
63// C++ [over.match.oper]p3 - enum restriction.
64float& operator==(E1, E2);
65
66void enum_test(Enum1 enum1, Enum2 enum2, E1 e1, E2 e2) {
67 float &f1 = (e1 == e2);
68 float &f2 = (enum1 == e2);
69 float &f3 = (e1 == enum2);
70 float &f4 = (enum1 == enum2); // expected-error{{non-const reference to type 'float' cannot be initialized with a temporary of type '_Bool'}}
71}
Douglas Gregor74253732008-11-19 15:42:04 +000072
73
74struct PostInc {
75 PostInc operator++(int);
76 PostInc& operator++();
77};
78
79struct PostDec {
80 PostDec operator--(int);
81 PostDec& operator--();
82};
83
84void incdec_test(PostInc pi, PostDec pd) {
85 const PostInc& pi1 = pi++;
86 const PostDec& pd1 = pd--;
87 PostInc &pi2 = ++pi;
88 PostDec &pd2 = --pd;
89}
90
91struct SmartPtr {
92 int& operator*();
93 // FIXME: spurious error: long& operator*() const;
94};
95
96void test_smartptr(SmartPtr ptr, const SmartPtr cptr) {
97 int &ir = *ptr;
98 // FIXME: reinstate long &lr = *cptr;
99}
Douglas Gregor337c6b92008-11-19 17:17:41 +0000100
101
102struct ArrayLike {
103 int& operator[](int);
104};
105
106void test_arraylike(ArrayLike a) {
107 int& ir = a[17];
108}
109
110struct SmartRef {
111 int* operator&();
112};
113
114void test_smartref(SmartRef r) {
115 int* ip = &r;
116}
117
118bool& operator,(X, Y);
119
120void test_comma(X x, Y y) {
121 bool& b1 = (x, y);
122 X& xr = (x, x);
123}