[Issue 1983] New: Big Hole in Const System
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Apr 10 02:24:12 PDT 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1983
Summary: Big Hole in Const System
Product: D
Version: 2.012
Platform: PC
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: caron800 at googlemail.com
There appears to be a large hole in the const system, demonstrated by the
following code.
import std.stdio;
class A
{
private int x_ = 1;
void x(int n) { x_ = n; }
int x() const { return x_; }
}
void main()
{
const(A) a = new A;
// The following correctly won't compile
// a.x = 2;
// a.x(2);
// **** BUT THIS WILL ****
(&a.x)(2);
writefln(a.x); // writes 2
}
The problem is that the expression (&a.x) has type
void delegate(int x)
wheras it /should/ have type
void delegate(int x) const
Unfortunately, there is no way to declare a const delegate (by which I mean, a
delegate whose context pointer is typed const).
I see this as a big problem. Without the ability to specify the constancy of
delegate contexts, it will be impossible to declare pure delegates. (If we ever
get parallel foreach, we're going to need pure delegates).
--
More information about the Digitalmars-d-bugs
mailing list