summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/eh/cond1.C
blob: 4f494267e4b72fd259d10eaa4cdf441e840ad664 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// PR c++/7050
// { dg-do run }

extern "C" void abort(void);

#define CI(stmt) try { stmt; abort(); } catch (int) { }

struct has_destructor
{
    ~has_destructor() { }
};

struct no_destructor
{
};

int PI(int& i) { return i++; }

int main(int argc, char *argv[])
{
    (argc+1 ? has_destructor() : throw 0);
    CI((argc+1 ? throw 0 : has_destructor()));
    CI((0 ? has_destructor() : throw 0));
    CI((1 ? throw 0 : has_destructor()));
    (0 ? throw 0 : has_destructor());
    (1 ? has_destructor() : throw 0);

    (argc+1 ? no_destructor() : throw 0);
    CI((argc+1 ? throw 0 : no_destructor()));
    CI((0 ? no_destructor() : throw 0));
    CI((1 ? throw 0 : no_destructor()));
    (0 ? throw 0 : no_destructor());
    (1 ? no_destructor() : throw 0);

    int i = 1;
    CI(throw PI(i));
    if (i != 2) abort();

    (1 ? 0 : throw PI(i));
    if (i != 2) abort();

    CI(0 ? 0 : throw PI(i));
    if (i != 3) abort();

    CI(0 ? has_destructor() : throw PI(i));
    if (i != 4) abort();
    (argc+1 ? has_destructor() : throw PI(i));
    if (i != 4) abort();

    i = 1;
    CI(throw i++);
    if (i != 2) abort();

    (1 ? 0 : throw i++);
    if (i != 2) abort();

    CI(0 ? 0 : throw i++);
    if (i != 3) abort();

    CI(0 ? has_destructor() : throw i++);
    if (i != 4) abort();
    (argc+1 ? has_destructor() : throw i++);
    if (i != 4) abort();
}