The following must be another manifestation of the same bug:
import std.stdio;
void main()
{
enum E { e0 }
foreach (format; [ "%s", "%d", "%u", "%3.7g", "%x", "%b" ]) {
writefln(format, E.e0);
}
}
Outputs:
e0
e0
e0
e0
e0
e0
Ali
On 2.059 Win32, the original test passes but the test of comment 1 throws an exception:
PS E:\DigitalMars\dmd2\samples> rdmd bug.d
e0
0
0
std.format.FormatException@E:\DigitalMars\dmd2\windows\bin\..\..\src\phobos\std\format.d(1178): integral
Comment #6 by acehreli — 2012-04-20T18:55:09Z
The problem at comment 5 can be reduced to this:
import std.stdio;
void main()
{
writefln("%f", 42); // COMPILATION ERROR
}
It looks like an integral cannot be matched to a floating point format specifier. (The same problem with "%g", etc.)
I have mixed feelings about this. Although 42 is definitely not a floating point type, it is implicitly converted to one according to language rules.
Comment #7 by k.hara.pg — 2012-04-22T17:55:41Z
(In reply to comment #6)
> The problem at comment 5 can be reduced to this:
>
> import std.stdio;
>
> void main()
> {
> writefln("%f", 42); // COMPILATION ERROR
> }
>
> It looks like an integral cannot be matched to a floating point format
> specifier. (The same problem with "%g", etc.)
>
> I have mixed feelings about this. Although 42 is definitely not a floating
> point type, it is implicitly converted to one according to language rules.
This is not allowed in current std.format implementation.
Original issue was already fixed, so I'll close this issue. If you think integer value should be formatted with "%f", please open new enhancement request.