]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gdc.test/compilable/test17590.d
d: Import dmd b8384668f, druntime e6caaab9, phobos 5ab9ad256 (v2.098.0-beta.1)
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / compilable / test17590.d
CommitLineData
b4c522fa
IB
1// REQUIRED_ARGS: -o-
2
3void lazyfun(scope lazy int a) @nogc;
4
5// Test that returning a local _static_ struct does not lead to allocation of a closure.
6auto 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.
17auto 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.
28static assert(!__traits(compiles, () @nogc => goo(1)));
29static assert(__traits(compiles, () => goo(1)));
30auto 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}