[Bug c++/94041] [10 Regression] temporary object destructor called before the end of the full-expression since r10-5577

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Mar 5 10:23:00 GMT 2020


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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Runtime test:

struct Temp { ~Temp(); };
struct A{ A(const Temp&) noexcept;  };
struct B{ ~B(); };
struct Pair{ A a; B b; };

Temp make_temp() noexcept;
void foo(const Pair&) noexcept;

void bar(const Pair& p) noexcept
{
    foo({A(make_temp()), p.b});
}


bool gone;
Temp::~Temp() { gone = true; }
A::A(const Temp&) noexcept { }
B::~B() { }

Temp make_temp() noexcept { return {}; }
void foo(const Pair&) noexcept { if (gone) __builtin_abort(); }

int main()
{
  Pair p{ Temp{}, {} };
  gone = false;
  bar(p);
}


More information about the Gcc-bugs mailing list