Sample program:
```
void testVariadic(T)(int nargs, ...)
{
foreach(i; 0 .. nargs)
{
auto arg = va_arg!T(_argptr);
}
}
struct Postblit
{
static int count = 0;
int value;
// ??? nothrow needed on X86 and X86_64
this(this) nothrow { count++; }
}
void test2()
{
auto a0 = Postblit(0);
auto a1 = Postblit(1);
auto a2 = Postblit(2);
testVariadic!Postblit(3, a0, a1, a2);
printf("Postblit called %d times\n", Postblit.count);
}
```
This prints:
Postblit called 6 times
Comment #1 by ibuclaw — 2020-04-26T15:16:48Z
Considering this a druntime bug. However I think the proper fix would also involve a compiler change as well.
e.g: In the druntime implementation:
static if (!__traits(isPOD, T))
{
// Passed by reference...
}
else
{
// Passed by value...
}
This requires the compiler to pass the objects by invisible reference in the first place.
Comment #2 by kinke — 2020-04-26T19:20:45Z
(In reply to Iain Buclaw from comment #0)
> Postblit called 6 times
Which is correct - 3 argument copies + 3 copies returned by va_arg. Unless va_arg is supposed to return a *moved* instance of the original argument.
Comment #3 by robert.schadek — 2024-12-07T13:40:09Z