March 08, 2021
https://issues.dlang.org/show_bug.cgi?id=21692

          Issue ID: 21692
           Summary: Non-mutable extern(D) scope class instances cannot be
                    created.
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: thomas.bockman@gmail.com

stackConstD and stackImutD should be allowed in the program below, just like the other combinations. Alternatively, if there is some good reason for this restriction, a better error message is needed, because construction is not modification.

extern(C++) class C { }
extern(D) class D { }

void main() {
    scope stackConstC = new const(C)();
    scope stackConstD = new const(D)(); // Error: cannot modify const
expression stackConstD
    auto gcConstD = new const(D)();

    scope stackImutC = new immutable(C)();
    scope stackImutD = new immutable(D)(); // Error: cannot modify immutable
expression stackImutD
    auto gcImutD = new immutable(D)();
}

--