summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/fail_compilation/fail20108.d
blob: 15845e1d2fcc3f6769f4fec93db102d6f45c5c14 (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
// REQUIRED_ARGS: -preview=dip1000
/*
TEST_OUTPUT:
---
fail_compilation/fail20108.d(15): Error: address of variable `y` assigned to `x` with longer lifetime
fail_compilation/fail20108.d(16): Error: scope parameter `x` may not be returned
fail_compilation/fail20108.d(23): Error: address of variable `y` assigned to `x` with longer lifetime
fail_compilation/fail20108.d(24): Error: scope variable `x` may not be returned
---
*/

@safe auto test(scope int* x)
{
    int y = 69;
    x = &y; //bad
    return x;
}

@safe auto test2()
{
    scope int* x;
    int y = 69;
    x = &y; //bad
    return x;
}

void main()
{
    auto y = test(null);
    auto z = test2();
}