#include struct X { inline static int Xnum = 0; int num; X() : num{++Xnum} { std::cout << "+X " << num << "\n"; } ~X() { std::cout << "-X " << num << "\n"; } X(const X& that) : num{that.num} { std::cout << "+X copy " << num << "\n"; } void operator=(const X& that) { num = that.num; std::cout << "=X copy " << num << "\n"; } }; auto throw_1() { throw 1; } struct C { std::string f; C(std::string const& fn) : f{fn} { std::cout << "enter " << f << "\n"; } ~C() { std::cout << "exit " << f << "\n"; } }; //------------------------------------------------------- // 0x: Test one level of out and immediate throw f00: () throws = { _:C="f00"; x: X; f01(out x); } f01: (out x: X) throws = { _:C="f01"; x=(); throw_1(); } //------------------------------------------------------- // 1x: Test multiple levels of out and intermediate throw f10: () throws = { _:C="f10"; x: X; f11(out x); } f11: (out x: X) throws = { _:C="f11"; f12(out x); } f12: (out x: X) throws = { _:C="f12"; f13(out x); throw_1(); } f13: (out x: X) throws = { _:C="f13"; f14(out x); } f14: (out x: X) throws = { _:C="f14"; x=(); } int main() { C c("main"); try { f00(); } catch (int) {} std::cout << "\n"; try { f10(); } catch (int) {} }