-
-
Notifications
You must be signed in to change notification settings - Fork 593
/
test17450.d
60 lines (51 loc) · 1.3 KB
/
test17450.d
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
/*
REQUIRED_ARGS: -preview=dip1000
TEST_OUTPUT:
---
fail_compilation/test17450.d(17): Error: returning `&s.bar` escapes a reference to parameter `s`
fail_compilation/test17450.d(16): perhaps annotate the parameter with `return`
fail_compilation/test17450.d(20): Error: returning `&this.bar` escapes a reference to parameter `this`
fail_compilation/test17450.d(19): perhaps annotate the function with `return`
---
*/
// https://issues.dlang.org/show_bug.cgi?id=17450
alias dg_t = void delegate();
struct S {
@safe dg_t foo1(ref S s) {
return &s.bar;
}
@safe dg_t foo2() {
return &bar;
}
@safe dg_t foo3(return ref S s) {
return &s.bar;
}
@safe dg_t foo4() return {
return &bar;
}
@safe void bar();
}
/*
TEST_OUTPUT:
---
fail_compilation/test17450.d(103): Error: scope parameter `c` may not be returned
fail_compilation/test17450.d(106): Error: scope parameter `this` may not be returned
---
*/
// https://issues.dlang.org/show_bug.cgi?id=17450
#line 100
class C {
@safe dg_t foo1(scope C c) {
return &c.bar;
}
@safe dg_t foo2() scope {
return &bar;
}
@safe dg_t foo3(return scope C c) {
return &c.bar;
}
@safe dg_t foo4() return scope {
return &bar;
}
@safe void bar();
}