Bug 11909 – Struct members and static arrays break pure function escape analysis (immutability violation)

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-01-12T18:45:00Z
Last change time
2014-01-26T13:52:37Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
code

Comments

Comment #0 by code — 2014-01-12T18:45:52Z
The following two programs should not compile (reduced from http://forum.dlang.org/post/[email protected]): --- 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.
Comment #1 by code — 2014-01-12T18:51:18Z
(Note: Even though issue 11503 has a bounty on it, this was the bug that originally led to it.)
Comment #2 by code — 2014-01-12T18:53:10Z