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.