Debian Codegraph @

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

raw
1 /***************************************************/
2
3 struct S1
4 {
5 int x;
6 ~this() {}
7 }
8
9 __gshared S1* s1ptr;
10
11 S1 test1a()
12 {
13 auto result = S1(123);
14 (() @trusted { result.x++; s1ptr = &result; })();
15 return result;
16 }
17
18 void test1()
19 {
20 auto r = test1a();
21 assert(r.x == 124);
22 assert(&r == s1ptr);
23 }
24
25 /***************************************************/
26 // https://github.com/dlang/dmd/issues/20567
27
28 struct S2
29 {
30 int x;
31 this(ref S2 s) { x = s.x; }
32 }
33
34 S2 returnRval(ref S2 arg1, ref S2 arg2, int i)
35 {
36 return i ? arg1 : arg2;
37 }
38
39 void test2()
40 {
41 S2 s1, s2;
42 s1.x = 3;
43 s2.x = 4;
44 S2 s = returnRval(s1, s2, 0);
45 assert(s.x == 4);
46 s = returnRval(s1, s2, 1);
47 assert(s.x == 3);
48 }
49
50 /***************************************************/
51
52 void main()
53 {
54 test1();
55 test2();
56 }