www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22799] New: opApply() delegates not required to be scope


          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 puremagic.com
          Reporter: bugzilla 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

  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.

Feb 20 2022