[Issue 12118] New: Modify immutable data using throw
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Feb 9 04:56:58 PST 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12118
Summary: Modify immutable data using throw
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: tim.dlang at t-online.de
--- Comment #0 from Tim <tim.dlang at t-online.de> 2014-02-09 04:56:54 PST ---
It is possible to throw an immutable Exception and catch it as mutable. Using
this immutable data can be modified.
Example Code:
class Dummy: Exception
{
int[] data;
@safe pure nothrow this(immutable int[] data) immutable
{
super("Dummy");
this.data = data;
}
}
@safe pure void modifyImmutable(immutable int[] data)
{
try
{
immutable Dummy e = new immutable Dummy(data);
throw e;
}
catch(Dummy e)
{
e.data[1] = 42;
}
}
@safe pure void main()
{
immutable int[] data = [1,2,3];
assert(data == [1,2,3]);
modifyImmutable(data);
assert(data == [1,42,3]);
}
--
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