Trying to respond to another question, and for fun, I've written the following silly program that try to convert an old C-style variadic function arguments list with a new one C++-style variadic template argument list (also in wandbox)
#include <cstdarg>
#include <iostream>
#include <stdexcept>
template <typename ... Args>
void bar (Args const & ... args)
{
using unused = int[];
(void)unused { (std::cout << args << ", ", 0)... };
std::cout << std::endl;
}
template <typename ... Ts>
void foo (int num, ...)
{
if ( num != sizeof...(Ts) )
throw std::runtime_error("!");
va_list args;
va_start(args, num);
bar( va_arg(args, Ts)... );
va_end(args);
}
int main ()
{
foo<int, long, long long>(3, 1, 2L, 3LL); // print 1, 2, 3,
}
But clang++ and execute it without problem, g++ give the following error
prog.cc: In function 'void foo(int, ...)':
prog.cc:26:25: error: expansion pattern 'va_arg(args, Ts)' contains no argument packs
bar( va_arg(args, Ts)... );
^~~
As usual: who's right? g++ or clang++?
ADDENDUM
Changing the line
bar( va_arg(args, Ts)... );
in
bar( ((void)Ts{}, va_arg(args, Ts))... );
the program is compiled by both compilers but, executing it, the clang++ version print
1, 2, 3,
(as espected) when the g++ version revert the values and print
3, 2, 1,