Behaviour of alias this changed
kenji hara
k.hara.pg at gmail.com
Tue May 8 22:10:37 PDT 2012
2012/5/9 H. S. Teoh <hsteoh at quickfur.ath.cx>:
> 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.
This is a Phobos regression in git head (and maybe in 2.059).
Please file this in bugzilla.
Kenji Hara
----
import std.traits;
struct S {
short[4] data;
alias data this;
string toString() { return "<S>"; }
}
void main()
{
S s;
static assert(isStaticArray!S); // succeeds in 2.059, failed in
2.058 and earlier
toImpl!string(s); // matches to static array version
}
extern(C) int printf(const char*, ...);
void toImpl(T, S)(S s)
if (is(S == struct) && is(typeof(&S.init.toString)) &&
isSomeString!T)
{
printf("1:\n");
}
void toImpl(T, S)(ref S s)
if (isStaticArray!S)
{
printf("2:\n");
}
More information about the Digitalmars-d
mailing list