summaryrefslogtreecommitdiffhomepage
path: root/CompilerDriver/cc2/regression-tests/mixed-out-destruction.cpp2
blob: 3637d6dd15059cbaa08aa9512be2a016260e4aee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>

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) {}
}