gcc/testsuite/g++.dg/expr/cast4.C
raw| 1 | // { dg-do run } |
| 2 | // PR c++/22132 |
| 3 | |
| 4 | extern "C" void abort (); |
| 5 | |
| 6 | struct foo { |
| 7 | int a; |
| 8 | int b; |
| 9 | }; |
| 10 | |
| 11 | class Foobar : public foo { |
| 12 | public: |
| 13 | Foobar() { a = 1; b = 2; } |
| 14 | virtual ~Foobar() {} |
| 15 | }; |
| 16 | |
| 17 | Foobar obj; |
| 18 | const Foobar* objPtr = &obj; |
| 19 | foo* f = (foo*)objPtr; |
| 20 | |
| 21 | int main () { |
| 22 | if (f->a != 1 || f->b != 2) |
| 23 | abort (); |
| 24 | } |
| 25 |