[Issue 9780] New: Maybe bad formatted write of array of 2-tuples

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 21 11:26:27 PDT 2013


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

           Summary: Maybe bad formatted write of array of 2-tuples
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2013-03-21 11:26:27 PDT ---
This is wrong code because %(...%) is currently not supposed to be able to
unpack a tuple:


import std.stdio: writefln;
import std.typecons: tuple;
void main() {
    auto data = [tuple(1, 2), tuple(3, 4), tuple(5, 6)];
    writefln("%(%s %s\n%)", data);
}



DMD 2.063alpha prints:

Tuple!(int, int)(1, 2) %s
Tuple!(int, int)(3, 4) %s
Tuple!(int, int)(5, 6)


I am not sure, but I think the printing of "%s" is a bug. I think that program
should raise a formatting error like in this case:


import std.stdio: writefln;
import std.typecons: tuple;
void main() {
    writefln("%s %s", tuple(1, 2));
}


std.format.FormatException at C:\dmd2\src\phobos\std\format.d(431): Orphan format
specifier: %%s %s

(Generally I hate D/DMD to not give compile-time errors for this. But this is a
different topic.)

-- 
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