Open
Description
Bugzilla Link | 12286 |
Version | trunk |
OS | All |
CC | @DougGregor,@seanbaxter,@mizvekov,@tavianator,@yuanfang-chen |
Extended Description
If an exception is thrown after a non-POD return value is successfully constructed in the return slot but before the returning function terminates, the value in the return slot is not destroyed. This can be clearly seen in the following test case. The really easy solution would be to push an inactive destructor cleanup in the prologue and activate it whenever evaluation completes for a return value, but that wouldn't be the correct ordering of destruction as specified in [except.ctor]p1. Needs more thought.
#include <stdio.h>
struct A {
A() { printf("creating A at %p\n", this); }
A(const A &a) { printf("copying A at %p into %p\n", &a, this); }
~A() { printf("destroying A at %p\n", this); }
};
struct B {
B() { printf("entering B\n"); }
~B() { printf("exiting B, throwing!\n"); throw 0; }
};
A test() {
B b;
return A();
}
int main() {
try {
printf("running\n");
A a = test();
} catch (int i) {
printf("caught\n");
}
}