https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92407
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org,
| |jason at gcc dot gnu.org
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I think it is well defined.
Simplified testcase:
struct A
{
A () { a++; }
A (const A &) { a++; }
~A () { a--; }
static int a;
};
int A::a = 0;
A
foo ()
{
int cnt = 10;
lab:
A a;
if (cnt--)
goto lab;
return a;
}
int
main ()
{
foo ();
if (A::a)
__builtin_abort ();
}
I believe the reason why this doesn't work is NRV, at least if return a; is
changed to return A ();, so that the a variable is not NRV optimized, it works
properly.