https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92423
Bug ID: 92423
Summary: Reference assigned from a ternary results in
destructor call
Product: gcc
Version: 9.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: tpg+gcc at mutabah dot net
Target Milestone: ---
The following code compiles with g++ 9.2.0, but calls `Foo`'s destructor twice.
```
#include <cstdio>
struct Foo
{
Foo() {
printf("Foo()\n");
}
Foo(const Foo& x) = delete;
Foo(Foo&& x) = delete;
Foo& operator=(const Foo&) = delete;
Foo& operator=(Foo&&) = delete;
~Foo() {
printf("~Foo()\n");
}
};
int main() {
Foo base_foo;
const auto& my_foo = (true ? base_foo : throw "");
printf("Selected a foo\n");
return 0;
}
```