www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7981] New: immutable structs by default have mutable constructor


           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 puremagic.com
        ReportedBy: malicious.wizard gmail.com

Consider following code:

    immutable struct Foo {
        this(int) { }

        void bar() { }

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


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: -------
Apr 24 2012