Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/gdc.dg/gdc283.d @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 // https://bugzilla.gdcproject.org/show_bug.cgi?id=283 | |
2 // { dg-do run { target hw } } | |
3 | |
4 struct Impl | |
5 { | |
6 size_t _count; | |
7 } | |
8 | |
9 struct RefCountedStore | |
10 { | |
11 Impl* _store; | |
12 | |
13 void initialize() | |
14 { | |
15 import core.stdc.stdlib : malloc; | |
16 _store = cast(Impl*) malloc(Impl.sizeof); | |
17 _store._count = 1; | |
18 } | |
19 | |
20 bool isInitialized() | |
21 { | |
22 return _store !is null; | |
23 } | |
24 | |
25 void ensureInitialized() | |
26 { | |
27 if (!isInitialized) | |
28 initialize(); | |
29 } | |
30 } | |
31 | |
32 struct RefCounted14443 | |
33 { | |
34 RefCountedStore _refCounted; | |
35 | |
36 this(int) | |
37 { | |
38 _refCounted.initialize(); | |
39 } | |
40 | |
41 this(this) | |
42 { | |
43 ++_refCounted._store._count; | |
44 } | |
45 | |
46 ~this() | |
47 { | |
48 if (--_refCounted._store._count) | |
49 return; | |
50 | |
51 import core.stdc.stdlib : free; | |
52 free(_refCounted._store); | |
53 _refCounted._store = null; | |
54 } | |
55 | |
56 int refCountedPayload() | |
57 { | |
58 _refCounted.ensureInitialized(); | |
59 return 1; | |
60 } | |
61 } | |
62 | |
63 struct PathRange14443 | |
64 { | |
65 RefCounted14443 path; | |
66 | |
67 @property PathElement14443 front() | |
68 { | |
69 return PathElement14443(this, path.refCountedPayload()); | |
70 } | |
71 } | |
72 | |
73 struct PathElement14443 | |
74 { | |
75 PathRange14443 range; | |
76 | |
77 this(PathRange14443 range, int) | |
78 { | |
79 this.range = range; | |
80 } | |
81 } | |
82 | |
83 void main() | |
84 { | |
85 auto path = RefCounted14443(12); | |
86 if (path._refCounted._store._count != 1) | |
87 assert(0); | |
88 { | |
89 auto _r = PathRange14443(path); | |
90 if (path._refCounted._store._count != 2) | |
91 assert(0); | |
92 { | |
93 auto element = _r.front; | |
94 if (path._refCounted._store._count != 3) | |
95 assert(0); | |
96 } | |
97 if (path._refCounted._store._count != 2) | |
98 assert(0); | |
99 } | |
100 if (path._refCounted._store._count != 1) | |
101 assert(0); | |
102 } |