[Issue 22799] New: opApply() delegates not required to be scope

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Feb 20 23:40:33 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=22799

          Issue ID: 22799
           Summary: opApply() delegates not required to be scope
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: bugzilla at digitalmars.com

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.

--


More information about the Digitalmars-d-bugs mailing list