[Bug c++/92407] Destruction of objects returned from functions skipped by goto

Dave.Poston at gs dot com gcc-bugzilla@gcc.gnu.org
Thu Nov 7 12:47:00 GMT 2019


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

--- Comment #1 from Dave Poston <Dave.Poston at gs dot com> ---
In fact, fill() isn't even needed.

Smaller repro:
https://godbolt.org/z/ubXl7Y

-----------------------
#include<iostream>

struct MyStruct
{
    MyStruct() {
        std::cout << "Constructed" << std::endl;
    }
    ~MyStruct() {
        std::cout << "Destructed" << std::endl;
    }
    int a;
};

MyStruct problem() {
    int cnt = 100;
start:
    MyStruct a;
    if( cnt-- )
        goto start;
    return a;
}

int main( int argc, char** argv )
{
    problem();
    return 0;
}


More information about the Gcc-bugs mailing list