www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.ide
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript
electronics




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

↑ ↓ ← 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
→ d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2054





------- Comment #1 from simen.kjaras gmail.com  2008-04-28 19:07 -------
(In reply to comment #0)
 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
→ d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2054





------- Comment #2 from brunodomedeiros+bugz gmail.com  2008-04-28 20:54 -------
(In reply to comment #1)
 (In reply to comment #0)
 void main()
 {
         char ch = 'd';
         invariant Struct iStruct = {&ch};

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