[Issue 13640] New: can break immutability with inout
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Oct 19 13:51:34 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=13640
Issue ID: 13640
Summary: can break immutability with inout
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: DMD
Assignee: nobody at puremagic.com
Reporter: ag0aep6g at gmail.com
struct Array()
{
int* p;
static struct Range
{
int* p;
inout this(inout ref int* p) {this.p = p;}
}
/* Return type is not inout; shouldn't compile: */
Range r() inout
{
return inout(Range)(p);
}
}
void main()
{
immutable int x = 42;
auto a = immutable(Array!())(&x);
auto r = a.r();
pragma(msg, typeof(r.p)); /* "int*" -- mutable, woops */
*r.p = 13; /* Shouldn't compile. */
assert(&x == r.p); /* Passes as it's supposed to. */
assert(x == 42); /* Passes, wat. */
assert(*r.p == 13); /* Passes, wat. */
assert(x == *r.p); /* Finally an assert that fails. */
}
--
More information about the Digitalmars-d-bugs
mailing list