1#include <cstdlib>
2
3int side_effect = 0;
4
5struct B { int dummy = 2324; };
6struct C {
7 void *operator new(std::size_t size) { void *p = ::operator new(size); side_effect = 3; return p; }
8 void *operator new[](std::size_t size) { void *p = ::operator new(size); side_effect = 4; return p; }
9 void operator delete(void *p) { std::free(ptr: p); side_effect = 1; }
10 void operator delete[](void *p) { std::free(ptr: p); side_effect = 2; }
11
12 B b;
13 B* operator->() { return &b; }
14 int operator->*(int) { return 2; }
15 int operator+(int) { return 44; }
16 int operator+=(int) { return 42; }
17 int operator++(int) { return 123; }
18 int operator++() { return 1234; }
19 int operator-(int) { return 34; }
20 int operator-=(int) { return 32; }
21 int operator--() { return 321; }
22 int operator--(int) { return 4321; }
23
24 int operator*(int) { return 51; }
25 int operator*=(int) { return 52; }
26 int operator%(int) { return 53; }
27 int operator%=(int) { return 54; }
28 int operator/(int) { return 55; }
29 int operator/=(int) { return 56; }
30 int operator^(int) { return 57; }
31 int operator^=(int) { return 58; }
32
33 int operator|(int) { return 61; }
34 int operator|=(int) { return 62; }
35 int operator||(int) { return 63; }
36 int operator&(int) { return 64; }
37 int operator&=(int) { return 65; }
38 int operator&&(int) { return 66; }
39
40 int operator~() { return 71; }
41 int operator!() { return 72; }
42 int operator!=(int) { return 73; }
43 int operator=(int) { return 74; }
44 int operator==(int) { return 75; }
45
46 int operator<(int) { return 81; }
47 int operator<<(int) { return 82; }
48 int operator<=(int) { return 83; }
49 int operator<<=(int) { return 84; }
50 int operator>(int) { return 85; }
51 int operator>>(int) { return 86; }
52 int operator>=(int) { return 87; }
53 int operator>>=(int) { return 88; }
54
55 int operator,(int) { return 2012; }
56 int operator&() { return 2013; }
57
58 int operator()(int) { return 91; }
59 int operator[](int) { return 92; }
60
61 operator int() { return 11; }
62 operator long() { return 12; }
63
64 // Make sure this doesn't collide with
65 // the real operator int.
66 int operatorint() { return 13; }
67 int operatornew() { return 14; }
68};
69
70int main(int argc, char **argv) {
71 C c;
72 int result = c->dummy;
73 result = c->*4;
74 result += c+1;
75 result += c+=1;
76 result += c++;
77 result += ++c;
78 result += c-1;
79 result += c-=1;
80 result += c--;
81 result += --c;
82
83 result += c * 4;
84 result += c *= 4;
85 result += c % 4;
86 result += c %= 4;
87 result += c / 4;
88 result += c /= 4;
89 result += c ^ 4;
90 result += c ^= 4;
91
92 result += c | 4;
93 result += c |= 4;
94 result += c || 4;
95 result += c & 4;
96 result += c &= 4;
97 result += c && 4;
98
99 result += ~c;
100 result += !c;
101 result += c!=1;
102 result += c=2;
103 result += c==2;
104
105 result += c<2;
106 result += c<<2;
107 result += c<=2;
108 result += c<<=2;
109 result += c>2;
110 result += c>>2;
111 result += c>=2;
112 result += c>>=2;
113
114 result += (c , 2);
115 result += &c;
116
117 result += c(1);
118 result += c[1];
119
120 result += static_cast<int>(c);
121 result += static_cast<long>(c);
122 result += c.operatorint();
123 result += c.operatornew();
124
125 C *c2 = new C();
126 C *c3 = new C[3];
127
128 //% self.expect("expr c->dummy", endstr=" 2324\n")
129 //% self.expect("expr c->*2", endstr=" 2\n")
130 //% self.expect("expr c + 44", endstr=" 44\n")
131 //% self.expect("expr c += 42", endstr=" 42\n")
132 //% self.expect("expr c++", endstr=" 123\n")
133 //% self.expect("expr ++c", endstr=" 1234\n")
134 //% self.expect("expr c - 34", endstr=" 34\n")
135 //% self.expect("expr c -= 32", endstr=" 32\n")
136 //% self.expect("expr c--", endstr=" 4321\n")
137 //% self.expect("expr --c", endstr=" 321\n")
138 //% self.expect("expr c * 3", endstr=" 51\n")
139 //% self.expect("expr c *= 3", endstr=" 52\n")
140 //% self.expect("expr c % 3", endstr=" 53\n")
141 //% self.expect("expr c %= 3", endstr=" 54\n")
142 //% self.expect("expr c / 3", endstr=" 55\n")
143 //% self.expect("expr c /= 3", endstr=" 56\n")
144 //% self.expect("expr c ^ 3", endstr=" 57\n")
145 //% self.expect("expr c ^= 3", endstr=" 58\n")
146 //% self.expect("expr c | 3", endstr=" 61\n")
147 //% self.expect("expr c |= 3", endstr=" 62\n")
148 //% self.expect("expr c || 3", endstr=" 63\n")
149 //% self.expect("expr c & 3", endstr=" 64\n")
150 //% self.expect("expr c &= 3", endstr=" 65\n")
151 //% self.expect("expr c && 3", endstr=" 66\n")
152 //% self.expect("expr ~c", endstr=" 71\n")
153 //% self.expect("expr !c", endstr=" 72\n")
154 //% self.expect("expr c!=1", endstr=" 73\n")
155 //% self.expect("expr c=1", endstr=" 74\n")
156 //% self.expect("expr c==1", endstr=" 75\n")
157 //% self.expect("expr c<1", endstr=" 81\n")
158 //% self.expect("expr c<<1", endstr=" 82\n")
159 //% self.expect("expr c<=1", endstr=" 83\n")
160 //% self.expect("expr c<<=1", endstr=" 84\n")
161 //% self.expect("expr c>1", endstr=" 85\n")
162 //% self.expect("expr c>>1", endstr=" 86\n")
163 //% self.expect("expr c>=1", endstr=" 87\n")
164 //% self.expect("expr c>>=1", endstr=" 88\n")
165 //% self.expect("expr c,1", endstr=" 2012\n")
166 //% self.expect("expr &c", endstr=" 2013\n")
167 //% self.expect("expr c(1)", endstr=" 91\n")
168 //% self.expect("expr c[1]", endstr=" 92\n")
169 //% self.expect("expr static_cast<int>(c)", endstr=" 11\n")
170 //% self.expect("expr static_cast<long>(c)", endstr=" 12\n")
171 //% self.expect("expr c.operatorint()", endstr=" 13\n")
172 //% self.expect("expr c.operatornew()", endstr=" 14\n")
173 //% self.expect("expr (new struct C); side_effect", endstr=" = 3\n")
174 //% self.expect("expr (new struct C[1]); side_effect", endstr=" = 4\n")
175 //% self.expect("expr delete c2; side_effect", endstr=" = 1\n")
176 //% self.expect("expr delete[] c3; side_effect", endstr=" = 2\n")
177 delete c2;
178 delete[] c3;
179 return 0;
180}
181

source code of lldb/test/API/lang/cpp/operators/main.cpp