www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9780] New: Maybe bad formatted write of array of 2-tuples

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 puremagic.com
        ReportedBy: bearophile_hugs eml.cc



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 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: -------
Mar 21 2013