This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/49917] New: g++.dg/init/for1.C wrong?
- From: "marc.glisse at normalesup dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 30 Jul 2011 19:48:14 +0000
- Subject: [Bug c++/49917] New: g++.dg/init/for1.C wrong?
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49917
Summary: g++.dg/init/for1.C wrong?
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: marc.glisse@normalesup.org
Hello,
I am having trouble understanding the test g++.dg/init/for1.C (copied below for
reference). For me, i and r are both 0 at first. a gets created. The loop
iterates twice, so i is 2 (not 1). a gets destroyed (so r is set to 1) and the
test returns 1. I noticed this because unrelated local patches cause a
testsuite failure.
#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;
}