gcc/testsuite/g++.old-deja/g++.jason/ref9.C
raw| 1 | // { dg-do run } |
| 2 | // Bug: g++ re-evaluates the initializer for r before calling f(); since i has |
| 3 | // changed to an invalid index, this breaks. |
| 4 | |
| 5 | class C |
| 6 | { |
| 7 | public: |
| 8 | void f () { } |
| 9 | }; |
| 10 | |
| 11 | void foo (C * objs[]) |
| 12 | { |
| 13 | int i = 0; |
| 14 | C & r = * objs[i]; /* make reference to element */ |
| 15 | |
| 16 | i = 666; |
| 17 | r.f (); /* core dumps here */ |
| 18 | } |
| 19 | |
| 20 | int |
| 21 | main () |
| 22 | { |
| 23 | C * objs[1] = { new C }; |
| 24 | |
| 25 | foo (objs); |
| 26 | } |