Debian Codegraph @

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

raw
1 /*
2 REQUIRED_ARGS: -preview=dip1000
3 TEST_OUTPUT:
4 ---
5 fail_compilation/test17450.d(17): Error: escaping a reference to parameter `s` by returning `&s.bar` is not allowed in a `@safe` function
6 fail_compilation/test17450.d(16): perhaps annotate the parameter with `return`
7 fail_compilation/test17450.d(20): Error: escaping a reference to parameter `this` by returning `&this.bar` is not allowed in a `@safe` function
8 fail_compilation/test17450.d(19): perhaps annotate the function with `return`
9 ---
10 */
11 // https://issues.dlang.org/show_bug.cgi?id=17450
12
13 alias dg_t = void delegate();
14
15 struct S {
16 @safe dg_t foo1(ref S s) {
17 return &s.bar;
18 }
19 @safe dg_t foo2() {
20 return &bar;
21 }
22
23 @safe dg_t foo3(return ref S s) {
24 return &s.bar;
25 }
26 @safe dg_t foo4() return {
27 return &bar;
28 }
29
30 @safe void bar();
31 }
32
33 /*
34 TEST_OUTPUT:
35 ---
36 fail_compilation/test17450.d(103): Error: scope parameter `c` may not be returned
37 fail_compilation/test17450.d(106): Error: scope parameter `this` may not be returned
38 ---
39 */
40 // https://issues.dlang.org/show_bug.cgi?id=17450
41
42 #line 100
43
44 class C {
45 @safe dg_t foo1(scope C c) {
46 return &c.bar;
47 }
48 @safe dg_t foo2() scope {
49 return &bar;
50 }
51
52 @safe dg_t foo3(return scope C c) {
53 return &c.bar;
54 }
55 @safe dg_t foo4() return scope {
56 return &bar;
57 }
58
59 @safe void bar();
60 }