D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 626 - std.format.doFormat accepts non-string arrays with any format specifier
Summary: std.format.doFormat accepts non-string arrays with any format specifier
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D1 (retired)
Hardware: x86 All
: P3 normal
Assignee: Andrei Alexandrescu
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2006-12-02 13:37 UTC by Matti Niemenmaa
Modified: 2014-02-15 13:29 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Matti Niemenmaa 2006-12-02 13:37:29 UTC
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 Andrei Alexandrescu 2010-09-13 20:26:11 UTC
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.