[Issue 20169] New: Cannot allocate immutable class on the stack with scope

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Aug 26 14:05:35 UTC 2019


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

          Issue ID: 20169
           Summary: Cannot allocate immutable class on the stack with
                    scope
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: atila.neves at gmail.com

----------------------
class Foo {
    this(int i) immutable {}
}

void main() {
    scope foo = new immutable Foo(42);
}
-----------------------

Fails to compile with:

huh.d(6): Error: cannot modify immutable expression foo


It works as expected if `auto` is used instead of `scope`.

--


More information about the Digitalmars-d-bugs mailing list