Bug 9462 – Delegate breaks immutability

Status
RESOLVED
Resolution
DUPLICATE
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-02-06T12:39:00Z
Last change time
2015-02-24T03:03:57Z
Keywords
accepts-invalid
Assigned to
nobody
Creator
maxim

Comments

Comment #0 by maxim — 2013-02-06T12:39:37Z
This should not work, since alternative ways of doing so (including manual creation of delegate object and initialization of .ptr and .funcptr properties is rejected) are banned. import std.stdio; struct S { int i; void bar() { ++i; } void foo() immutable { //bar(); //error (&bar)(); //works, lang hole } } void main() { immutable S s; writeln(s.i); s.foo(); writeln(s.i); } dmd is smart enough to avoid delegate allocation, it just issues call directly to bar()
Comment #1 by maxim — 2013-02-06T12:55:41Z
Forgot to mention: void delegate() dg = &bar; dg(); also is accepted.
Comment #2 by k.hara.pg — 2015-02-24T03:03:57Z
*** This issue has been marked as a duplicate of issue 1983 ***