Debian Codegraph @

gcc/testsuite/gdc.test/runnable/test19393.d

raw
1 string result;
2
3 struct S
4 {
5 this(this)
6 {
7 result ~= "A";
8 }
9
10 ~this()
11 {
12 result ~= "B";
13 }
14 }
15
16 void foo(const(S)[] ar...)
17 {
18 /* postblit gets called on this initialization,
19 * then when the function returns, the destructor
20 * gets called => result = "AB";
21 */
22 auto d = ar[0];
23 }
24
25 void bar()
26 {
27 /* S(null) needs to be destroyed after the function call,
28 * that means that another `B` is appended => result = "ABB"
29 */
30 foo(S());
31 }
32
33 void main()
34 {
35 bar();
36 assert(result == "ABB");
37 }