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: [email protected]
ReportedBy: [email protected]
--- Comment #0 from David Nadlinger <[email protected]> 2014-01-12 18:45:52
PST ---
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.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------