[Issue 2625] Creating new struct with literal bypasses immutability of members if struct is in array
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Apr 1 13:06:44 PDT 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2625
dsimcha at yahoo.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |critical
Keywords|spec |accepts-invalid
Summary|Inconsistent behavior with |Creating new struct with
|const/immutable struct |literal bypasses
|members |immutability of members if
| |struct is in array
------- Comment #1 from dsimcha at yahoo.com 2009-04-01 15:06 -------
Upon thinking about this some more, it's pretty clear that one should *not* be
able to change the value in an existing memory location by creating a whole new
struct, i.e. the following is bad:
struct Pair {
immutable uint g1;
uint g2;
}
void main() {
Pair[1] stuff;
stuff[0] = Pair(1, 2); // Modify immutable by rebinding whole struct.
}
Note that the same thing happens if stuff is a dynamic array instead of a
static array. Upping severity, giving more descriptive title.
--
More information about the Digitalmars-d-bugs
mailing list