Bug 6892 – Formatted write with specified length of enum member

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2011-11-05T04:04:00Z
Last change time
2012-04-22T17:55:51Z
Keywords
pull
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2011-11-05T04:04:51Z
import std.stdio, std.traits; enum Foo { A }; void main() { writefln(">%12s<", "A"); Foo[] foos = [EnumMembers!Foo]; writefln(">%12s<", foos[0]); } Output dmd 2.057head: > A< >A< Expected output: > A< > A<
Comment #1 by acehreli — 2012-02-27T22:45:48Z
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
Comment #2 by k.hara.pg — 2012-02-28T17:12:09Z
Comment #3 by github-bugzilla — 2012-03-01T09:20:32Z
Commit pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/b5256c57f64fa823ca8ba200d343674d6556c75c Merge pull request #465 from 9rnsr/fix6892 Issue 6892 - Formatted write with specified length of enum member
Comment #4 by github-bugzilla — 2012-03-08T22:54:49Z
Commit pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/12571977d821a2e7e7a799012baea3e8f73dee0d fix Issue 6892 - Formatted write with specified length of enum member
Comment #5 by lovelydear — 2012-04-20T17:12:03Z
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.