See the comments for stuff that makes the problem go away:
---
import std.stdio;
import std.string;
// "Manually" instantiating this template function (changing it into
// a regular function with void[0] argument) makes the problem disappear.
void foo(T)(T t) {
/*
// It even fails if this is put in (so below code isn't reached).
return null;
//*/
// It works if this is removed:
static if (is(typeof(T.nonexistant)))
{}
}
void main() {
/*
// Shows that long.max.stringof is wrong:
writefln(long.max);
writefln(long.max.stringof);
//*/
/*
// Shows the problem more exactly:
// (namely, the first 2 bytes of long.max.stringof are wrong)
foreach(char c; format(long.max)) {
writef("%02x ", c);
}
writefln();
foreach(char c; long.max.stringof) {
writef("%02x ", c);
}
writefln();
//*/
assert(long.max.stringof == format(long.max)); // fails
// Remove this or change the argument to something
// other than a static array and it works.
foo([]);
}
---
Comment #1 by fvbommel — 2007-05-07T09:42:15Z
Another interesting case, likely related:
---
import std.stdio;
import std.string;
void main() {
writefln(long.max.stringof);
writefln(ulong.max.stringof);
}
---
The first three bytes of long.max.stringof seem to be overwritten by "-1\0".
ulong.max.stringof is incorrectly displayed as "-1".
If you change the order, the first three characters of long.max.stringof overwrite the characters of ulong.max.stringof (including the trailing \0).
Comment #2 by aldacron — 2007-05-07T10:20:34Z
[email protected] wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=1219
>
>
>
>
>
> ------- Comment #1 from [email protected] 2007-05-07 09:42 -------
> Another interesting case, likely related:
> ---
> import std.stdio;
> import std.string;
>
> void main() {
> writefln(long.max.stringof);
> writefln(ulong.max.stringof);
> }
> ---
> The first three bytes of long.max.stringof seem to be overwritten by "-1\0".
> ulong.max.stringof is incorrectly displayed as "-1".
> If you change the order, the first three characters of long.max.stringof
> overwrite the characters of ulong.max.stringof (including the trailing \0).
I've seen similar things, and I think it is related to the ".". It can
happen to floating-point numbers as well, when they contain a decimal point.