Debian Codegraph @

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

raw
1 // REQUIRED_ARGS: -preview=dip1000
2
3 // https://issues.dlang.org/show_bug.cgi?id=22916
4 // Issue 22916 - [dip1000] copy of ref return still treated as scope variable (edit)
5
6 @safe:
7 struct Arr
8 {
9 int** ptr;
10 ref int* index() return scope { return *ptr; }
11 void assign(int* p) scope { *ptr = p; }
12 }
13
14 void main0()
15 {
16 scope Arr a;
17 a.assign(a.index());
18 }
19
20 // https://issues.dlang.org/show_bug.cgi?id=23682
21 ref char* front_p(ref return scope char** p) { return *p; }
22 ref char* front_r( return scope char** p) { return *p; }
23
24 char* g;
25
26 void test23862()
27 {
28 scope char** _errors;
29 g = front_p(_errors); // should pass
30 g = front_r(_errors); // should pass
31 }
32
33 // Test case reduced from druntime
34 ref int* monitor(return scope Object h) pure nothrow @nogc @trusted
35 {
36 return *cast(int**)&h.__monitor;
37 }
38
39 int* getMonitor(Object h) pure @nogc
40 {
41 return monitor(h); // should pass
42 }