auto with array of strings (BUG?)

Justin mrjnewt at gmail.com
Wed Aug 19 16:01:29 PDT 2009


I was writing some unittests when I ran across some rather unexpected behavior in which strings in an array were being trimmed to the length of the first element. Running this program:

import std.stdio;
void main() {
	auto strings = ["hello", "cruelly", "innovative", "world"];
	writefln(strings);
}

produces this:
[[h,e,l,l,o],[c,r,u,e,l],[i,n,n,o,v],[w,o,r,l,d]]

as the compiler decides to make the strings variable an array of char[5u]. The problem is easily avoided by replacing auto with string[], but the problem caught me off guard while working in the one place where I regularly use auto: unittests.

Is there a reason that the compiler makes the assumptions it does or is this a bug? I did try searching the bugzilla with a few different queries, but failed to turn up anything that looked likely.



More information about the Digitalmars-d mailing list