[Issue 4927] writefln silently ignores arguments not present in the format string
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Jun 29 20:33:17 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=4927
--- Comment #5 from bearophile_hugs at eml.cc 2013-06-29 20:33:16 PDT ---
(In reply to comment #4)
> *** Issue 10489 has been marked as a duplicate of this issue. ***
The body of Issue 10489:
In DMD 2.064alpha this program compiles and runs with no errors, warnings or
run-time exceptions:
import std.stdio;
void main() {
writefln("%d %d", 1, 2, 3);
}
While this gives a run-time exception:
import std.string;
void main() {
format("%d %d", 1, 2, 3);
}
std.format.FormatException at ...\dmd2\src\phobos\std\string.d(2346): Orphan
format arguments: args[2..3]
To catch some programmer mistakes I suggest to turn this into an
exception/error:
writefln("%d %d", 1, 2, 3);
But as stated by Andrei Alexandrescu:
http://forum.dlang.org/post/kqgna8$1ese$1@digitalmars.com
> The only point I'd negotiate would be to not throw with positional
> arguments, and throw with sequential arguments. All code that cares uses
> positional specifiers anyway.
So according to Andrei this should be accepted:
import std.stdio;
void main() {
writefln("%2$s %1$s", 1, 2, 3);
}
Currently this is accepted (and it prints "A B10"), but I think it should be
not accepted:
import std.stdio;
void main() {
writefln("A%2$s B%1$s", 10);
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list