gcc/testsuite/g++.dg/init/for1.C
raw| 1 | // PR c++/13865 |
| 2 | // Bug: We were destroying 'a' before executing the loop. |
| 3 | |
| 4 | // { dg-do run } |
| 5 | |
| 6 | #include <stdio.h> |
| 7 | |
| 8 | int i; |
| 9 | int r; |
| 10 | |
| 11 | class A |
| 12 | { |
| 13 | public: |
| 14 | A() { printf("A ctor\n"); } |
| 15 | ~A() |
| 16 | { |
| 17 | printf("A dtor\n"); |
| 18 | if (i != 2) |
| 19 | r = 1; |
| 20 | } |
| 21 | }; |
| 22 | |
| 23 | int main(int argc, char **argv) |
| 24 | { |
| 25 | for (A a; i < 2; ++i) { |
| 26 | printf("iteration %d\n", i); |
| 27 | } |
| 28 | |
| 29 | return r; |
| 30 | } |