www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20632] New: Format and writeln not usable with non-copyable

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

          Issue ID: 20632
           Summary: Format and writeln not usable with non-copyable types
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Keywords: rejects-valid
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: pro.mathias.lang gmail.com

It is probably the evidence of a larger problem, and fixing it is probably
limited by fixes to the ABI, but here it goes:
```
import std.stdio;

private struct MyStruct
{
    int a;
    string b;

     disable this(this);
     disable ref MyStruct opAssign(ref MyStruct other);
}

void main ()
{
    MyStruct s;
    writeln(s);
}
```

This code *should* compile. We should be able to take a value by ref and just
format or print it. This is quite important when you have `extern(C++)` types
where copy is expensive.

Even adding my own `toString` to it:
```
    string toString()  safe pure nothrow  nogc { return "WhyNot"; }
```

does not make it compile.

--
Mar 03