1 // REQUIRED_ARGS: -preview=dip1021
3 /* Should compile successfully
12 void canFind(scope Allocation
);
17 void borrow(scope int*);
18 void borrow2c(const scope int*, const scope int*);
22 /*****************************/
24 @live int* foo1(int* p
)
26 return p
; // consumes owner
32 return p
; // consumes owner
35 @live int* foo3(int* p
)
37 scope int* q
= p
; // borrows from p
38 return p
; // use of p ends borrow in q
41 @live int* foo4(int* p
)
43 scope int* bq
= p
; // borrow
44 scope const int* cq
= p
; // const borrow
45 return p
; // ends both borrows
48 /*******************************/
57 /*******************************/
59 void deallocate(int* ptr
, size_t length
) @live
61 canFind(Allocation(ptr
, length
)); // canFind() borrows ptr
66 /*******************************/
107 out1(p
); // initialize
112 /*******************************/
118 zoo1(*p
); // does not consume p
123 int** p
= cast(int**)malloc();
124 free(*p
); // consumes p
128 int[] a
= malloc()[0 .. 1];
129 zoo1(a
[0]); // does not consume a
130 free(a
.ptr
); // consumes a
134 int*[] a
= (cast(int**)malloc())[0 .. 1];
135 free(a
[0]); // consumes a
138 struct S
{ int i
; int* p
; }
141 S
* s
= cast(S
*)malloc();
142 zoo1(s
.i
); // does not consume s
147 S
* s
= cast(S
*)malloc();
148 free(s
.p
); // consumes s