aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/compilable/vgc3.d
blob: 4bf889ce9974c1568da7d4357f9eaa4dbfd79544 (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
// REQUIRED_ARGS: -vgc -o-
// PERMUTE_ARGS:

/***************** AssignExp *******************/

/*
TEST_OUTPUT:
---
compilable/vgc3.d(16): vgc: setting 'length' may cause GC allocation
compilable/vgc3.d(17): vgc: setting 'length' may cause GC allocation
compilable/vgc3.d(18): vgc: setting 'length' may cause GC allocation
---
*/
void testArrayLength(int[] a)
{
    a.length = 3;
    a.length += 1;
    a.length -= 1;
}

/***************** CallExp *******************/

void barCall();

/*
TEST_OUTPUT:
---
---
*/


void testCall()
{
    auto fp = &barCall;
    (*fp)();
    barCall();
}

/****************** Closure ***********************/

@nogc void takeDelegate2(scope int delegate() dg) {}
@nogc void takeDelegate3(      int delegate() dg) {}

/*
TEST_OUTPUT:
---
compilable/vgc3.d(51): vgc: using closure causes GC allocation
compilable/vgc3.d(63): vgc: using closure causes GC allocation
---
*/
auto testClosure1()
{
    int x;
    int bar() { return x; }
    return &bar;
}
void testClosure2()
{
    int x;
    int bar() { return x; }
    takeDelegate2(&bar);     // no error
}
void testClosure3()
{
    int x;
    int bar() { return x; }
    takeDelegate3(&bar);
}