This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/86769] New: g++ destroys condition variable in for statement too early


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86769

            Bug ID: 86769
           Summary: g++ destroys condition variable in for statement too
                    early
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: richard-gccbugzilla at metafoo dot co.uk
  Target Milestone: ---

Testcase:

struct X { ~X(); operator bool(); };
void f(X &);
void g() { for (; X x = X(); f(x)); }

GCC miscompiles this by destroying the 'x' variable before the call to 'f(x)'.
Per C++ [stmt.for]p1, the above is equivalent to

while (X x = X()) {
  f(x);
}

So the 'x' variable should be destroyed *after* the third operand of the
for-statement is evaluated, not before.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]