Bug 10489 – Orphan format arguments exception/error for writeln unless they are

Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-06-27T12:20:00Z
Last change time
2013-06-29T20:05:48Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2013-06-27T12:20:04Z
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@...\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/[email protected] > 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); }
Comment #1 by andrej.mitrovich — 2013-06-29T20:05:48Z
*** This issue has been marked as a duplicate of issue 4927 ***