[Issue 7981] New: immutable structs by default have mutable constructor

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 24 13:33:30 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7981

           Summary: immutable structs by default have mutable constructor
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: malicious.wizard at gmail.com


--- Comment #0 from Alex <malicious.wizard at gmail.com> 2012-04-24 13:34:32 PDT ---
Consider following code:

    immutable struct Foo {
        this(int) { }

        void bar() { }
    }

    int main(in string[] args) {
        auto foo = Foo(1);

        foo.bar();
    }

This will not work out, because `bar()` is immutable, but `foo` is not. If
constructor is declared as `this(int) immutable {}`, it will work again.
Default no-arg constructor for immutable structs is already immutable, so
shouldn't other constructor also be considered immutable implicitly, much like
methods are?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list