[Issue 20632] New: Format and writeln not usable with non-copyable types
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Wed Mar  4 02:05:19 UTC 2020
    
    
  
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 at puremagic.com
          Reporter: pro.mathias.lang at 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.
--
    
    
More information about the Digitalmars-d-bugs
mailing list