blob: 3de3f1e1b6187ec38458e377bdbfc9a4a245e456 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
// expect: 0 5 15 5 0/
// destructors 6.15.3: an unreachable cycle of five values with drops is finalized whole by one collection, each value once, then freed
include rt;
int n, sum;
word g;
struct node { node* next; int v; void drop() { n++; sum = sum + this.v; } }
unchecked fn make() {
node* a = rt.new(node); node* p = a; int i;
a.v = 1;
for (i = 2; i <= 5; i++) { node* q = rt.new(node); q.v = i; p.next = q; p = q; }
p.next = a;
g = a;
return 0;
}
fn main() {
make();
rt.gc(); rt.put_n(n); rt.put_c(32);
g = 0;
rt.gc(); rt.put_n(n); rt.put_c(32); rt.put_n(sum); rt.put_c(32);
rt.gc(); rt.put_n(n); rt.put_c(32);
rt.put_n(rt.dcount); rt.put_c(10);
return 0;
}
// zc0: skip
|