• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <cstdlib>
2 
3 int side_effect = 0;
4 
5 struct B { int dummy = 2324; };
6 struct C {
operator newC7   void *operator new(std::size_t size) { void *p = ::operator new(size); side_effect = 3; return p; }
operator new[]C8   void *operator new[](std::size_t size) { void *p = ::operator new(size); side_effect = 4; return p; }
operator deleteC9   void operator delete(void *p) { std::free(p); side_effect = 1; }
operator delete[]C10   void operator delete[](void *p) { std::free(p); side_effect = 2; }
11 
12   B b;
operator ->C13   B* operator->() { return &b; }
operator ->*C14   int operator->*(int) { return 2; }
operator +C15   int operator+(int) { return 44; }
operator +=C16   int operator+=(int) { return 42; }
operator ++C17   int operator++(int) { return 123; }
operator ++C18   int operator++() { return 1234; }
operator -C19   int operator-(int) { return 34; }
operator -=C20   int operator-=(int) { return 32; }
operator --C21   int operator--() { return 321; }
operator --C22   int operator--(int) { return 4321; }
23 
operator *C24   int operator*(int) { return 51; }
operator *=C25   int operator*=(int) { return 52; }
operator %C26   int operator%(int) { return 53; }
operator %=C27   int operator%=(int) { return 54; }
operator /C28   int operator/(int) { return 55; }
operator /=C29   int operator/=(int) { return 56; }
operator ^C30   int operator^(int) { return 57; }
operator ^=C31   int operator^=(int) { return 58; }
32 
operator |C33   int operator|(int) { return 61; }
operator |=C34   int operator|=(int) { return 62; }
operator ||C35   int operator||(int) { return 63; }
operator &C36   int operator&(int) { return 64; }
operator &=C37   int operator&=(int) { return 65; }
operator &&C38   int operator&&(int) { return 66; }
39 
operator ~C40   int operator~() { return 71; }
operator !C41   int operator!() { return 72; }
operator !=C42   int operator!=(int) { return 73; }
operator =C43   int operator=(int) { return 74; }
operator ==C44   int operator==(int) { return 75; }
45 
operator <C46   int operator<(int) { return 81; }
operator <<C47   int operator<<(int) { return 82; }
operator <=C48   int operator<=(int) { return 83; }
operator <<=C49   int operator<<=(int) { return 84; }
operator >C50   int operator>(int) { return 85; }
operator >>C51   int operator>>(int) { return 86; }
operator >=C52   int operator>=(int) { return 87; }
operator >>=C53   int operator>>=(int) { return 88; }
54 
operator ,C55   int operator,(int) { return 2012; }
operator &C56   int operator&() { return 2013; }
57 
operator ()C58   int operator()(int) { return 91; }
operator []C59   int operator[](int) { return 92; }
60 
operator intC61   operator int() { return 11; }
operator longC62   operator long() { return 12; }
63 
64   // Make sure this doesn't collide with
65   // the real operator int.
operatorintC66   int operatorint() { return 13; }
operatornewC67   int operatornew() { return 14; }
68 };
69 
main(int argc,char ** argv)70 int 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