]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gdc.test/fail_compilation/test16193.d
d: Import dmd b8384668f, druntime e6caaab9, phobos 5ab9ad256 (v2.098.0-beta.1)
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / fail_compilation / test16193.d
CommitLineData
b4c522fa 1/*
5fee5ec3 2REQUIRED_ARGS: -preview=dip1000
b4c522fa
IB
3TEST_OUTPUT:
4---
5fee5ec3
IB
5fail_compilation/test16193.d(38): Error: function `test16193.abc` is `@nogc` yet allocates closures with the GC
6fail_compilation/test16193.d(40): test16193.abc.__foreachbody2 closes over variable x at fail_compilation/test16193.d(39)
b4c522fa
IB
7---
8*/
5fee5ec3
IB
9//fail_compilation/test16193.d(22): To enforce `@safe`, the compiler allocates a closure unless `opApply()` uses `scope`
10//fail_compilation/test16193.d(34): To enforce `@safe`, the compiler allocates a closure unless `opApply()` uses `scope`
11//fail_compilation/test16193.d(41): To enforce `@safe`, the compiler allocates a closure unless `opApply()` uses `scope`
b4c522fa
IB
12
13// https://issues.dlang.org/show_bug.cgi?id=16193
14
15struct S {
16 int opApply(int delegate(int) dg) @nogc;
17}
18
19void foo() {
20 int x = 0;
21 foreach(i; S.init) {
22 x++;
23 }
24}
25
26struct T {
27 int opApply(scope int delegate(int) dg) @nogc;
28}
29
30
31void bar() @nogc {
32 int x = 0;
33 foreach(i; T.init) {
34 x++;
35 }
36}
37
38void abc() @nogc {
39 int x = 0;
40 foreach(i; S.init) {
41 x++;
42 }
43}
44