Debian Codegraph @

gcc/testsuite/gdc.test/compilable/test19097.d

raw
1 /* REQUIRED_ARGS: -preview=dip1000
2 */
3
4 // Related to: https://github.com/dlang/dmd/pull/8504
5
6 @safe:
7
8 void betty()(ref int* r, return scope int* p)
9 {
10 r = p; // infer `scope` for r
11 }
12
13 void boop()(ref int* r, scope int* p)
14 {
15 r = p; // infer `scope` for r, `return` for p
16 }
17
18 void foo(scope int* pf)
19 {
20 scope int* rf;
21 betty(rf, pf);
22 boop(rf, pf);
23 }
24
25 // https://issues.dlang.org/show_bug.cgi?id=22801
26 struct Wrapper
27 {
28 int* ptr;
29
30 this(return ref int var) @safe
31 {
32 this.ptr = &var;
33 }
34 }
35
36 void main() @safe
37 {
38 int i;
39 auto w = Wrapper(i);
40 auto wt = WrapperT!()(i);
41 }
42
43 void assign(ref scope int* x, return ref int y) @safe
44 {
45 x = &y;
46 }
47
48 // https://issues.dlang.org/show_bug.cgi?id=22967
49 // inference of `return ref` when assigned to first parameter
50 struct WrapperT()
51 {
52 int* ptr;
53
54 this(ref int var) @safe
55 {
56 this.ptr = &var;
57 }
58
59 static void assignInferred(ref scope int* xi, ref int yi) @safe
60 {
61 xi = &yi;
62 }
63 }