www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8956] New: Ability to break typesystem with constructor/postblit/destructor (e.g. modify immutable)

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8956

           Summary: Ability to break typesystem with
                    constructor/postblit/destructor (e.g. modify
                    immutable)
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: verylonglogin.reg gmail.com



16:47:40 MSK ---
As was mentioned in Issue 4338 and Issue 4867 one is able to break typesystem
using postblit/destructor. But that's not all. Constructor also can be used for
this.

Example:
---
int* p1, p2, p3;

struct S
{
    int* p;

    this(int* p) { p1 = this.p = p; }
    this(this)   { p2 = p; }
    ~this()      { p3 = p; }
}

void main()
{
    immutable s = immutable S(new int); // call constructor
    { immutable tmp = s; } // call postblit and destructor
    assert(p1 is s.p && p2 is s.p && p3 is s.p);
}
---

The worst is that it can be done accidentally. E.g.:
---
struct S
{
    int* p;
    this(int* p) { this.p = p; } // Looks really innocuous, isn't it?
}

void main()
{
    int i;
    immutable s = immutable S(&i); // Feel constructor's destructive power!
    assert(&i is s.p);
}
---


Please, create enhancement requests as other issues and add e.g. `Depends on`
links here.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 03 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8956


Denis Shelomovskij <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |8958



18:01:11 MSK ---
The first fix proposal: Issue 8958

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 03 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8956


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid
                 CC|                            |smjg iname.com
             Blocks|                            |2573



this(int* i) has no const/immutable qualifier.  As such, if I remember
correctly, the compiler should not be allowing it to be used to construct an
immutable instance.  In any case, it's a bug that it accepts the call to it to
construct an immutable without having first checked that it's still valid when
the this pointer is immutable.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 04 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8956


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |maxim maxim-fomin.ru
         Resolution|                            |FIXED



---
It was fixed in 2.063 (now ctor attributes should correspond to those in
variable declarations).

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