]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gdc.test/compilable/test17590.d
Add D front-end, libphobos library, and D2 testsuite.
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / compilable / test17590.d
1 // REQUIRED_ARGS: -o-
2
3 void lazyfun(scope lazy int a) @nogc;
4
5 // Test that returning a local _static_ struct does not lead to allocation of a closure.
6 auto foo_static(int a, bool b) @nogc {
7 static struct SInside {}
8
9 SInside res;
10
11 lazyfun(a);
12
13 return res;
14 }
15
16 // Test that returning a local _non-static_ struct that does not reference any local variable does not lead to allocation of a closure.
17 auto foo_nonstatic(int a, bool b) @nogc {
18 struct SInside {}
19
20 SInside res;
21
22 lazyfun(a);
23
24 return res;
25 }
26
27 // Test that returning a local non-static struct that references a local variable does lead to allocation of a closure.
28 static assert(!__traits(compiles, () @nogc => goo(1)));
29 static assert(__traits(compiles, () => goo(1)));
30 auto goo(T)(T a) {
31 struct SInside {
32 T foo() { return a; }
33 }
34
35 SInside res;
36
37 lazyfun(a);
38
39 return res;
40 }