Bug 16279 – foreach and opApply cannot be nogc

Status
RESOLVED
Resolution
WORKSFORME
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2016-07-14T05:32:04Z
Last change time
2021-10-26T13:11:21Z
Assigned to
No Owner
Creator
TeddyBear12311

Comments

Comment #0 by TeddyBear12311 — 2016-07-14T05:32:04Z
If one tries to override onApply in a nogc setting, they cannot because marking the delegate nogc prevents foreach from working. One can't have both delegate types as a stranger error happens. This seems to be similar to https://issues.dlang.org/show_bug.cgi?id=15624
Comment #1 by moonlightsentinel — 2021-10-26T13:11:21Z
Overloading w.r.t. @nogc works since 2.080.1. Test case: struct Foo { int[3] arr = [1, 2, 3]; int opApply(scope int delegate(ref int) @nogc loopBody) @nogc { foreach(a; arr) loopBody(a); return 0; } int opApply(scope int delegate(ref int) loopBody) { foreach(a; arr) loopBody(a); return 0; } } void main() @nogc { Foo foo; int sum = 0; foreach(f; foo) { sum += f; } }