Summary: Returning a cast(immutable) struct erroneously calls a
                    matching constructor
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from S´┐Żnke Ludwig <> 2011-07-12 
12:40:53 PDT ---
The following snipped fails to compile. What seems to happen is that the return
statement implicitly calls the constructor which in turn returns a mutable S
which is not implicitly castable to immutable - thus the error.

Happens since DMD 2.054

struct S {
    int[] c;
    this(in S){}
    immutable(S) f() const {
        S s;
        return cast(immutable)s;
        // the following works:
        //immutable(S) sr = cast(immutable)s;
        //return sr;

dbug2.d(6): Error: cannot implicitly convert expression ((immutable
immutable(S) __ctmp3 = 0;
 , __ctmp3).this(s)) of type S to immutable(S)

.. leaving the severity as normal, as there is an easy workaround

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to