1 /* 2 REQUIRED_ARGS: -dip1000 3 PERMUTE_ARGS: 4 TEST_OUTPUT: 5 --- 6 fail_compilation/test16193.d(39): Error: function test16193.abc is @nogc yet allocates closures with the GC 7 fail_compilation/test16193.d(41): test16193.abc.__foreachbody1 closes over variable x at fail_compilation/test16193.d(40) 8 --- 9 */ 10 //fail_compilation/test16193.d(22): To enforce @safe compiler allocates a closure unless the opApply() uses 'scope' 11 //fail_compilation/test16193.d(34): To enforce @safe compiler allocates a closure unless the opApply() uses 'scope' 12 //fail_compilation/test16193.d(41): To enforce @safe compiler allocates a closure unless the opApply() uses 'scope' 13 14 // https://issues.dlang.org/show_bug.cgi?id=16193 15 16 struct S { 17 int opApply(int delegate(int) dg) @nogc; 18 } 19 foo()20void foo() { 21 int x = 0; 22 foreach(i; S.init) { 23 x++; 24 } 25 } 26 27 struct T { 28 int opApply(scope int delegate(int) dg) @nogc; 29 } 30 31 bar()32void bar() @nogc { 33 int x = 0; 34 foreach(i; T.init) { 35 x++; 36 } 37 } 38 abc()39void abc() @nogc { 40 int x = 0; 41 foreach(i; S.init) { 42 x++; 43 } 44 } 45 46