www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11909] New: Struct members and static arrays break pure function escape analysis (immutability violation)

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

           Summary: Struct members and static arrays break pure function
                    escape analysis (immutability violation)
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: code klickverbot.at


--- Comment #0 from David Nadlinger <code klickverbot.at> 2014-01-12 18:45:52
PST ---
The following two programs should not compile (reduced from
http://forum.dlang.org/post/mailman.327.1389464975.15871.digitalmars-d puremagic.com):

---
struct Data
{
    char[256] buffer;
     property const(char)[] filename() const pure {
        return buffer[];
    }
}

void test1()
{
    Data d;
    string f = d.filename;
    d.buffer[0] = 'a';
}

struct Data2
{
    char buffer;
}
---

---
 property const(char)[] filename(const ref Data2 d) pure nothrow
{
    return (&d.buffer)[0 .. 1];
}

 property const(char)[] filename2(const Data2* d) pure nothrow
{
    return (&d.buffer)[0 .. 1];
}

void test2()
{
    Data2 d;
    string f = d.filename;
    string g = (&d).filename2;
    d.buffer = 'a';
}
---

Similar to issue 11503.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 12 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11909


David Nadlinger <code klickverbot.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #1 from David Nadlinger <code klickverbot.at> 2014-01-12 18:51:18
PST ---
(Note: Even though issue 11503 has a bounty on it, this was the bug that
originally led to it.)

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 12 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11909



--- Comment #2 from David Nadlinger <code klickverbot.at> 2014-01-12 18:53:10
PST ---
https://github.com/D-Programming-Language/dmd/pull/3085

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 12 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11909


David Nadlinger <code klickverbot.at> changed:

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


-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 26 2014