[Issue 12767] New: writeln of a struct with toString returning char[N]

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon May 19 04:57:06 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=12767

          Issue ID: 12767
           Summary: writeln of a struct with toString returning char[N]
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P1
         Component: Phobos
          Assignee: nobody at puremagic.com
          Reporter: bearophile_hugs at eml.cc

struct Foo {
    char[3] toString() const pure {
        return ['F', 'o', 'o'];
    }
}
void main() {
    import std.stdio;
    Foo f;
    writeln(f);
}



DMD 2.066alpha gives:

...\dmd2\src\phobos\std\range.d(705,9): Error: static assert  "Cannot put a
char[3] into a LockingTextWriter."
...\dmd2\src\phobos\std\format.d(2575,12):        instantiated from here:
put!(LockingTextWriter, char[3])
...\dmd2\src\phobos\std\format.d(2846,21):        instantiated from here:
formatObject!(LockingTextWriter, Foo, char)
...\dmd2\src\phobos\std\format.d(3167,16):        instantiated from here:
formatValue!(LockingTextWriter, Foo, char)
...\dmd2\src\phobos\std\format.d(440,54):        ... (2 instantiations, -v to
show) ...
...\dmd2\src\phobos\std\stdio.d(2528,21):        instantiated from here:
write!(Foo, char)
temp.d(9,12):        instantiated from here: writeln!(Foo)



Returning a small fixed-size char array from a toString is sometimes useful to
allow tagging toString() with @nogc.


Perhaps related: Issue 12375

--


More information about the Digitalmars-d-bugs mailing list