The D ABI spec on how variadic functions are implemented has the two contradictory sentences: "The caller is expected to clean the stack. _argptr is not passed, it is computed by the callee."
Only one of these can be fulfilled. I suggest changing the ABI to mandate passing the variadic arguments as a pointer to the arguments (in the caller's stack frame).
This is also much more portable, making D easier to implement in a compiler for more than one architecture. For example, x86-64 does not use the stack for variadic arguments ...
Such an approach would also (as noted) make the "passing on" of vararg possible.
I would prefer if one finds a syntax to "switch off" the automatic generation of _argptr and arguments, and is able to pass them directly to the D function.
This cleanly solves most issues with vararg that come form portability (and gdc has many of them), has a small cost, but it should be ok. D (unlike C) does not allow one to call a function without having a declaration that shows that it is a vararg function, so one can safely disregard all C issues.
An issue that is still open is alignement: TypeInfo does not have that information and without it unpacking (and thus packing) the data cannot keep it into account.
I think that it is wrong to have pointers to the structure that do not respect its alignment requirements.
A last note: vararg is not made irrelevant by Variadic templates, because is some occasions one wants to avoid the extra code usage (but this is no show stopper, at least to me), and because sometime one wants to have a method in a class and using Variadic templates makes it final.
Comment #3 by tomas — 2008-10-23T06:18:09Z
I just realized I misread the docs. It's not contradictory, just not portable :/
I read it as "The _callee_ is expected to clean the stack..."
I wish the ABI would change to not use C-style varargs to implement this, this would make a lot of things possible with variadic that can't be done now.
But in any case this specific bug report is invalid :(