Antoine Morrier
Antoine Morrier

Reputation: 4078

macro variadic and empty macro variadic

I know that this is invalid

#define MACRO(x, ...) __VA_ARGS__
MACRO(5); // VA ARGS is empty, so is not good

However, is this valid ?

#define MACRO(x, ...)
MACRO(5);

On Wandbox, clang gives me a warning, gcc does not, and on my computer MSVC does not either.

Upvotes: 3

Views: 230

Answers (1)

P.W
P.W

Reputation: 26800

When tested with GCC (from version 5.1 to the latest 8.2) on godbolt.org, this results in a error with the -pedantic-errors option.

<source>:5:8: error: ISO C++11 requires at least one argument for the "..." in a variadic macro
 MACRO(5)

See it here.

You will have to wait for __VA_OPT__ (available from C++2a) to do what you are trying to do.

Upvotes: 2

Related Questions