https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103711
Sebastian Redl <sebastian.redl at getdesigned dot at> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |sebastian.redl@getdesigned.
| |at
--- Comment #2 from Sebastian Redl <sebastian.redl at getdesigned dot at> ---
Clang does not.
Here's an extended test case:
#include <iostream>
using namespace std;
int constructions = 0;
int destructions = 0;
struct A
{
A()
{
constructions++;
}
virtual ~A() {
destructions++;
}
};
struct B : public virtual A
{
B(int dummy)
{
};
B() : B(1) {
throw -1;
}
virtual ~B() = default;
};
struct C : public B
{
};
int main() {
try
{
B b;
}
catch (int e)
{
cout << "Caughtb: " << e << endl;
}
try
{
C c;
}
catch (int e)
{
cout << "Caughtc: " << e << endl;
}
cout << constructions << " constructions" << endl;
cout << destructions << " destructions" << endl;
}
Now GCC generates two versions of B::B(): one called by the complete object
construction on the stack, and one called by the base object construction in
C::C().
Unfortunately, both versions call the complete object destructor B::~B() in
their unwinding code, when the base object delegating constructor should call
the base object destructor.
Here's a godbolt link with the generated assembly:
https://godbolt.org/z/hEvYjrsGj