[Issue 9149] Disallow converting delegates to const

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue May 24 08:53:24 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=9149

--- Comment #5 from timon.gehr at gmx.ch ---
(In reply to timon.gehr from comment #4)
> (In reply to Sobirari Muhomori from comment #3)
> > How about this?
> > 
> > class A
> > {
> > 	int i;
> > 	const void delegate() dg;
> > 	this() pure { dg=&f; }
> > 	void f(){ i++; }
> > }
> > 
> > unittest
> > {
> > 	const A a = new A;
> > 	a.dg();
> > }
> 
> The assignment in the constructor shouldn't compile.

And indeed, DMD rejects the assignment.

--


More information about the Digitalmars-d-bugs mailing list