www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20770] New: error: cannot pass types that need destruction as

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

          Issue ID: 20770
           Summary: error: cannot pass types that need destruction as
                    variadic arguments
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ibuclaw gdcproject.org

Sample program:
```
import core.stdc.stdarg;
import core.stdc.stdio;

struct Foo
{
    int fld;
    //this(this) { }
    ~this() { }      // Make it non-POD.
}

void variableFoo(int num, ...)
{
    va_list va;
    va_start(va, num);
    foreach (i; 0 .. num)
    {
        auto arg = va_arg!Foo(va);
        printf("fld = %d\n", arg.fld);
    }
}

void main()
{
    auto f1 = Foo(1);
    auto f2 = Foo(2);
    auto f3 = Foo(3);
    variableFoo(3, f1, f2, f3);
}
```

There is no reason why internally these can't be passed by invisible reference.

va_arg!() will need to be fixed in order to support this.

--
Apr 26