Bug 22799 – opApply() delegates not required to be scope
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-02-20T23:40:33Z
Last change time
2022-02-21T08:24:22Z
Keywords
safe
Assigned to
No Owner
Creator
Walter Bright
Comments
Comment #0 by bugzilla — 2022-02-20T23:40:33Z
The spec https://dlang.org/spec/statement.html#foreach_over_struct_and_classes shows the delegate to be declared as `scope`. But the compiler does not enforce it:
struct S {
int opApply (/*scope*/ int delegate (int* ptr) @safe dg) @safe {
return 0;
}
}
void test(S s) @safe {
foreach (int* x; s)
{
}
}
compiles without error.
Comment #1 by bugzilla — 2022-02-20T23:56:59Z
The spec says:
"Best practice is to annotate delegate parameters with scope when possible."
so this bug is invalid.