www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8958] New: [RFC] Make constructors/postblits/destructors work correctly with const/immutable qualifiers


           Summary: [RFC] Make constructors/postblits/destructors work
                    correctly with const/immutable qualifiers
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: verylonglogin.reg gmail.com

--- Comment #0 from Denis Shelomovskij <verylonglogin.reg gmail.com> 2012-11-03
17:59:49 MSK ---
A proposal to fix Issue 8956 - Ability to break typesystem with

First, lets make them qualifier-overloadable.

Then let we have such struct:
class C { }

struct S0
{ int i; immutable int* p; }

struct S1
{ int i; int* p; }

struct S2
{ S1 s1; }

struct S
    int i;
    int* p;
    int[] darr;
    int[1] sarr;
    C c;
    S0* pS0;
    S1 s1;
    S1[1] sarrS1;
    S1* pS1;
    S2 s2;

    this(this) inout // e.g. a postblit
        // What will we see here?

In an `inout` ctor/postblit/dtor we will see fields as:

* For pointers and dynamic arrays, as a result of `cast()`:
    inout(int)* p;
    inout(int)[] arr;
    inout(S0)* pS0;
    inout(S1)* pS1;

* For class references
    * require Issue 5325 - Mutable references to const/immutable/shared classes
    inout(C)ref c;

* For types where `inout(T)` is assignable to `T` (primitive types, some
    int i;
    int[1] i;
    S0 s0;

* For all other types (structs/unions):
    inout(S1) s1;
    inout(S1[1]) sarrS1;
    inout(S2) s2;

    * But assignment is allowed:
        s1 = inout(S1)();
    * Assignment by index or property is allowed if it writes to (&this)[0 ..
1] memory:
        sarrS1[0] = inout(S1)();
        s2.s1 = inout(S1)();
        s2.s1.i = 5;
    * For its fields that are in (&this)[0 .. 1] memory same type-replacement
rules apply:
        is(typeof(s2.s1.i) == int)

This proposal can be consolidated in some analog of `inout(T)ref` from Issue
5325 but for structs with same syntax and one simple rule: it is mutable if it
is in (&this)[0 .. 1] memory.

You are welcome to find mistakes, improve, destroy or make a counter-proposal!

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