Merge from mainline
[official-gcc.git] / gcc / testsuite / g++.dg / opt / nrv11.C
blob2b72f790b6eeaa3d3a078bbb079dc89f6723d455
1 // PR middle-end/25977
2 // Bug: We were assuming that the return slot of the current function is
3 // always safe to use as the return slot for another call, because its
4 // address cannot escape.  But its address can escape if we perform the
5 // named return value optimization.
7 // { dg-do run }
9 struct A
11     A( int left, int top, int width, int height )
12       : x1(left), y1(top), x2(left+width-1), y2(top+height-1) {}
14     //A(const A& o) : x1(o.x1), y1(o.y1), x2(o.x2), y2(o.y2) {}
15     //A& operator=(const A& o ) { x1=o.x1; y1=o.y1; x2=o.x2; y2=o.y2; return *this; }
17     A  operator&(const A &r) const
18     {
19         A tmp(0, 0, -1, -1);
20         tmp.x1 = ((r.x1) < (x1) ? (x1) : (r.x1));
21         tmp.x2 = ((x2) < (r.x2) ? (x2) : (r.x2));
22         tmp.y1 = ((r.y1) < (y1) ? (y1) : (r.y1));
23         tmp.y2 = ((y2) < (r.y2) ? (y2) : (r.y2));
24         return tmp;
25     }
27     int x1;
28     int y1;
29     int x2;
30     int y2;
33 bool operator==( const A &r1, const A &r2 )
35     return r1.x1==r2.x1 && r1.x2==r2.x2 && r1.y1==r2.y1 && r1.y2==r2.y2;
38 static A test()
40     A all = A( 0, 0, 1024, 768);
41     A a = all;
42     A r = all;
43     a = a & r;
44     return a;
47 extern "C" void abort(void);
49 int main( int argc, char ** argv )
51     A all = A( 0, 0, 1024, 768);
52     A a = test();
54     if ( ! ( a == all))
55       abort();
57     return 0;