summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/fail_compilation/test14238.d
blob: 2d5f58630b22c6d24a5c2eeb518f3e85011a92d9 (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
/* REQUIRED_ARGS: -dip1000
   PERMUTE_ARGS:
   TEST_OUTPUT:
---
fail_compilation/test14238.d(21): Error: scope variable `fn` may not be returned
fail_compilation/test14238.d(29): Error: escaping reference to stack allocated value returned by `&baz`
---
*/
// https://issues.dlang.org/show_bug.cgi?id=14238

@safe:

alias Fn = ref int delegate() return;

ref int foo(return scope Fn fn)
{
    return fn(); // Ok
}

ref int foo2(scope Fn fn) {
    return fn(); // Error
}

ref int bar() {
    int x;
    ref int baz() {
            return x;
    }
    return foo(&baz);
}