]> gcc.gnu.org Git - gcc.git/commitdiff
re PR c++/13865 ([tree-ssa] dtor runs prematurely for loop-scoped variable)
authorJason Merrill <jason@gcc.gnu.org>
Fri, 30 Jan 2004 04:35:26 +0000 (23:35 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 30 Jan 2004 04:35:26 +0000 (23:35 -0500)
        PR c++/13865
        * c-simplify.c (gimplify_for_stmt): Reorganize to fix cleanups.

[[Split portion of a mixed commit.]]

From-SVN: r76923.2

gcc/testsuite/g++.dg/init/for1.C [new file with mode: 0644]

diff --git a/gcc/testsuite/g++.dg/init/for1.C b/gcc/testsuite/g++.dg/init/for1.C
new file mode 100644 (file)
index 0000000..02f8a2d
--- /dev/null
@@ -0,0 +1,28 @@
+// PR c++/13865
+// Bug: We were destroying 'a' before executing the loop.
+
+#include <stdio.h>
+
+int i;
+int r;
+
+class A
+{
+public:
+  A() { printf("A ctor\n"); }
+  ~A()
+  {
+    printf("A dtor\n");
+    if (i != 1)
+      r = 1;
+  }
+};
+
+int main(int argc, char **argv)
+{
+  for (A a; i < 2; ++i) {
+    printf("iteration %d\n", i);
+  }
+
+  return r;
+}
This page took 0.073624 seconds and 5 git commands to generate.