summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/runnable/auto1.d
blob: e68b06380ef5a14811f15db12ee8f9469e20ee7a (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125

import core.stdc.stdio;

/******************************************/

scope class Foo
{
    static int x;

    ~this()
    {
        printf("Foo.~this()\n");
        x++;
    }
}

int test1x()
{
    scope Foo f = new Foo();
    return 6;
}


void test1()
{
    {
        scope Foo f = new Foo();
    }
    int c;

    assert(Foo.x == 1);
    c = test1x();
    assert(c == 6);
    assert(Foo.x == 2);

    if (c != 6)
        scope Foo h = new Foo();
    assert(Foo.x == 2);

    if (c == 6)
        scope Foo j = new Foo();
    assert(Foo.x == 3);

    {
        scope Foo g = null, k = new Foo();
        assert(Foo.x == 3);
    }
    assert(Foo.x == 4);
}

/******************************************/

int ax;

scope class A2
{
  this()
  {
    printf("A2.this()\n");
    ax += 1;
  }

  ~this()
  {
    printf("A2.~this()\n");
    ax += 1000;
  }
};


void test2()
{
  {
    scope A2 a = new A2();
    printf("Hello world.\n");
  }
  assert(ax == 1001);
}



/******************************************/

int status3;

scope class Parent3
{
}

scope class Child3 : Parent3
{
        this(){
                assert(status3==0);
                status3=1;
        }

        ~this(){
                assert(status3==1);
                status3=2;
        }
}

void foo3()
{
        scope Parent3 o = new Child3();
        assert(status3==1);
}

void test3()
{
        foo3();
        assert(status3==2);
}

/******************************************/

int main()
{
    test1();
    test2();
    test3();

    printf("Success\n");
    return 0;
}