www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2054] New: Const system broken on struct assignment.

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

           Summary: Const system broken on struct assignment.
           Product: D
           Version: 2.012
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid
          Severity: critical
          Priority: P1
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: brunodomedeiros+bugz gmail.com


Const system broken on struct assignment:
---- ----
struct Struct { 
        char* chptr; 
}

void main()
{
        char ch = 'd';
        invariant Struct iStruct = {&ch};

        Struct y = iStruct; // BREAKAGE
        *y.chptr = 'X'; // Because now we can do this
}
---- ----
Like Andrei mentioned in accu-functional.pdf , such struct assignment should
only be allowed if the struct refered to no mutable memory (which is not the
case).


-- 
Apr 28 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2054







 void main()
 {
         char ch = 'd';
         invariant Struct iStruct = {&ch};
I would believe this to be just as wrong. Mutable is not implicitly castable to invariant, and ch might change even though iStruct assumes it does not. --
Apr 28 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2054








 void main()
 {
         char ch = 'd';
         invariant Struct iStruct = {&ch};
I would believe this to be just as wrong. Mutable is not implicitly castable to invariant, and ch might change even though iStruct assumes it does not.
Duh me, that's right of course. Massive distraction of mine :S --
Apr 28 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2054


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED





Fixed dmd 2.014


-- 
May 22 2008