www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12767] New: writeln of a struct with toString returning char[N]


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

struct Foo {
    char[3] toString() const pure {
        return ['F', 'o', 'o'];
void main() {
    import std.stdio;
    Foo 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

May 19 2014