I'm trying to create some trace macros that use variadic arguments. The macros only seem to function correctly when a named argument precedes the variadic ones.
A minimal code version of what I'm doing is shown below. Only TraceTest() without arguments fails. I have also tried to create an intermediate macro that passes a dummy first argument to TraceTest1, but that fails too.
template<typename ...Args>
inline void f(const char*, Args&&... args) { }
#define TraceTest1(a, args...) f("Trace Start ", ##args)
#define TraceTest(args...) f("Trace Start", ##args)
TraceTest(); // error: expected primary-expression before ‘)’ token
TraceTest("a"); // works
TraceTest1(); // works
TraceTest1("a"); // works
I have read the gnu docs on variadic macros but could find nothing that would explain this.
I am using gcc 7.4.0 under Ubuntu 18.04 and compiling with
g++ -Wall -Wextra -std=c++17 src/event.cpp -obin/event