Bug 626 – std.format.doFormat accepts non-string arrays with any format specifier

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2006-12-02T13:37:00Z
Last change time
2014-02-15T13:29:06Z
Keywords
wrong-code
Assigned to
andrei
Creator
matti.niemenmaa+dbugzilla

Comments

Comment #0 by matti.niemenmaa+dbugzilla — 2006-12-02T13:37:29Z
import std.stdio; void main() { int[] x = [1,2,3]; int[3] y = [1,2,3]; int* z = [1,2,3]; // work, incorrectly writefln("%3.2f", [1,2,3]); writefln("%3.2f", x); writefln("%3.2f", y); writefln("%d", [1,2,3]); writefln("%d", x); writefln("%d", y); writefln("--"); // fail, correctly writefln("%3.2f", z); writefln("%d", z); writefln("%3.2f", ['f','o','o']); }
Comment #1 by andrei — 2010-09-13T20:26:11Z
writefln("%d", [1,2,3]) works as designed - arrays pass down the format spec to each of their elements. http://www.dsource.org/projects/phobos/changeset/1998 takes care of the rest.