Bug 14103 – dmd doesn't treat opIn as unsafe

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2015-02-01T17:58:00Z
Last change time
2015-06-09T05:15:00Z
Assigned to
nobody
Creator
code

Comments

Comment #0 by code — 2015-02-01T17:58:49Z
cat > bug.d << CODE int foo(int[int] aa) @safe { auto p = 12 in aa; aa.remove(12); return *p; } CODE dmd -c bug ---- Here p is a pointer to the value stored in the AA. Used for anything else but a boolean comparison, `in` is an unsafe operation. ---- cat > bug.d << CODE int foo(int[] aa) @safe { auto p = &aa[12]; aa.length = 10; return *p; } CODE dmd -c bug ---- Ironically the similar operation on an array isn't treated as unsafe either.
Comment #1 by code — 2015-02-02T11:50:28Z
The array operation really isn't unsafe, because the existing array isn't freed upon reallocating. We can implement similar semantics for the AA without much performance cost, so I'll mark this bug as invalid.