[Issue 9149] Disallow converting delegates to const
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed May 25 08:28:14 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=9149
Steven Schveighoffer <schveiguy at yahoo.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |schveiguy at yahoo.com
--- Comment #10 from Steven Schveighoffer <schveiguy at yahoo.com> ---
I think the delegate assignment should be legal. The auto-conversion from pure
ctor to immutable should be illegal (note that converting to const is not a
good test case, because you can easily assign an A to a const A without
purity), because casting the A to immutable does not affect the 'this' pointer
of the delegate member, and that could point at the given object that you are
casting or any member. I had thought that the 'this' pointer was
const-agnostic. That is:
class C
{
void foo() {}
void ifoo() immutable {}
}
void main()
{
mc = new C;
ic = new C;
void delegate() x = &mc.foo;
x = &mc.ifoo; // why not?
}
Why does it matter if x's delegate has an immutable 'this'? that detail is
insignificant to the caller.
--
More information about the Digitalmars-d-bugs
mailing list