15.2 says "An object that is partially constructed or partially destroyed will
have destructors executed for all of its fully constructed base classes and
non-variant members, that is, for subobjects for which the principal
constructor (12.6.2) has completed execution and the destructor has not yet
begun execution." We do this for objects that are created via constructor, and
for array initialization, but not for aggregate initialization of a class:
struct A
{
A() {}
A(const A&) { throw 1; }
};
int bs;
struct B
{
B() { ++bs; }
B(const B&) { ++bs; }
~B() { --bs; }
};
struct C
{
B b1;
A a;
B b2;
};
int main()
{
{
B b1, b2;
A a;
try {
C c = { b1, a, b2 };
} catch (...) {}
}
return bs;
}
icc gets this right.
--
Summary: Partial aggregate initialization not cleaned up on
exception
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jason at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41449