Debian Codegraph @

gcc/testsuite/gdc.test/fail_compilation/diag23295.d

raw
1 /*
2 REQUIRED_ARGS: -preview=dip1000
3 TEST_OUTPUT:
4 ---
5 fail_compilation/diag23295.d(21): Error: assigning scope variable `x` to non-scope parameter `y` calling `foo` is not allowed in a `@safe` function
6 fail_compilation/diag23295.d(32): which is assigned to non-scope parameter `z`
7 fail_compilation/diag23295.d(34): which is not `scope` because of `f = & z`
8 fail_compilation/diag23295.d(24): Error: assigning scope variable `ex` to non-scope parameter `e` calling `thro` is not allowed in a `@safe` function
9 fail_compilation/diag23295.d(39): which is not `scope` because of `throw e`
10 ---
11 */
12
13 // explain why scope inference failed
14 // https://issues.dlang.org/show_bug.cgi?id=23295
15
16 @safe:
17
18 void main()
19 {
20 scope int* x;
21 foo(x, null);
22
23 scope Exception ex;
24 thro(ex);
25 }
26
27 auto foo(int* y, int** w)
28 {
29 fooImpl(y, null);
30 }
31
32 auto fooImpl(int* z, int** w)
33 {
34 auto f = &z;
35 }
36
37 auto thro(Exception e)
38 {
39 throw e;
40 }