Behaviour of alias this changed

H. S. Teoh hsteoh at quickfur.ath.cx
Tue May 8 10:30:53 PDT 2012


On Tue, May 08, 2012 at 10:15:00AM -0700, Ali Çehreli wrote:
> On 05/08/2012 10:11 AM, H. S. Teoh wrote:
> >I have some code along these lines:
> >
> >	struct S {
> >		short[4] data;
> >		alias this data;
> >
> >		string toString() { ... }
> >	}
> >	...
> >	S s;
> >	writeln(to!string(s));
> >
> >In dmd 2.059 (I believe) and earlier, this calls S.toString(). However,
> >in git dmd, this calls data.toString() instead.
> >
> >I'm just curious about the rationale for this change, and whether
> >there's a way to override the toString() call so that it always calls
> >S.toString()?
[...]
> Just a guess: It could be related to const-correctness improvements.
> Try defining S.toString() as const.
[...]

I tried that, it didn't help. Declaring string toString() const {...}
still has data.toString being called instead of S.toString.


T

-- 
Today's society is one of specialization: as you grow, you learn more and more about less and less. Eventually, you know everything about nothing.


More information about the Digitalmars-d mailing list