[Issue 10489] New: Orphan format arguments exception/error for writeln unless they are

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 27 12:20:05 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10489

           Summary: Orphan format arguments exception/error for writeln
                    unless they are
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2013-06-27 12:20:04 PDT ---
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