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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jan 12 18:45:56 PST 2014


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 at puremagic.com
        ReportedBy: code at klickverbot.at


--- Comment #0 from David Nadlinger <code at 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: -------


More information about the Digitalmars-d-bugs mailing list