c++: constantness of call to function pointer [PR111703]
[official-gcc.git] / gcc / testsuite / g++.dg / torture / pr95493-1.C
blob907d191ebfeb9bf5a1393cd8030a1f8497fe8d57
1 // { dg-do run { target c++11 } }
2 // PR rtl-optimization/95493 comment 8
4 #include <array>
5 #include <iostream>
7 struct Point
9     std::array<int, 3> array;
11     Point(int x, int y, int z) : array{x, y, z} {}
12     
13     Point(const Point & other) : array{other.array} {} // OK if commented
14     //Point(const Point &) = default; // OK
16     //Point(Point && other) = default; // OK
18     int  operator[] (std::size_t i) const { return array[i]; }
19     int& operator[] (std::size_t i)       { return array[i]; }
22 //using Point = std::array<int, 3>; // OK
24 struct Cell
26     Point point;
27     Cell(Point const& pt) : point(pt) {}
28     int   operator[] (std::size_t i) const { return point[i]; }
29     int&  operator[] (std::size_t i)       { return point[i]; }
32 //using Cell = Point; // OK
34 std::ostream & operator<< (std::ostream & out, Cell const& object)
35 //std::ostream & operator<< (std::ostream & out, Cell object) // Fails with f2 too
37     for ( std::size_t i = 0; i < 3; ++i )
38         out << object[ i ] << " ";
39     return out;
43 struct DirIterator
45     std::size_t dir;
46     Cell cell;
48     DirIterator(Cell c)
49         : dir(0), cell(c)
50     {
51         find(); // OK if commented
52     }
54     void find()
55     {
56         //while (dir < 3) // Fails with f2 too
57         while (dir < 3 && (cell[dir] % 2) == 0)
58             ++dir;
59     }
62 Cell uIncident(Cell c, std::size_t k)
63 //Cell uIncident(Cell& c, std::size_t k) // OK
65     --c[k];
66     return c;
69 Cell uSpel(Point p)
71     for (std::size_t i = 0; i < 3; ++i)
72         p[i] += p[i] + 1;
73     return Cell(p);
77 int main ()
79     Cell c = uSpel(Point{0, 0, 0}); // Fails
80     //Cell c( Point(1, 1, 1) ); // OK
82     auto q = DirIterator( c );
84     Cell f1 = uIncident( c, q.dir ); // Fails
85     //Cell f1 = uIncident( c, 0 ); // OK
87     Cell f2 = f1; // f2 is the right cell that f1 should be
89     std::cout << "q.dir = " << q.dir << " ; f1 = " << f1 << " ; f2 = " << f2 << std::endl;
90     //std::cout << "q.dir = " << q.dir << " ; f1 = " << f1[0] << " " << f1[1] << " " << f1[2] << " ; f2 = " << f2[0] << " " << f2[1] << " " << f2[2] << std::endl; // OK
92     for (int i = 0; i < 3; ++i)
93       if (f1[i] != f2[i])
94         __builtin_abort();