I want to suppress GCC variadic macro argument warning for zero arguments, produced for example by:
// for illustration purposes only:
int foo(int i) { return 0; };
#define FOO(A, ...) foo(A, ##__VA_ARGS__)
FOO(1);
^ warning: ISO C++11 requires at least one argument for the "..." in a variadic macro
for a particular macro definition within a source file when using GCC 5.3.0.
In clang this is done as follows:
// ... large file
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#define FOO(A, ...) foo(A, ##__VA_ARGS__)
#pragma clang diagnostic pop
// ... large file
// not necessary on the same file
FOO(1); // doesnt trigger the warning
In gcc it looks like -pedantic
is a magical kind of warning type so the following just doesn't work:
// ... large file
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
#define FOO(A, ...) foo(A, ##__VA_ARGS__)
#pragma GCC diagnostic pop
// ... large file
Just to be clear, the warning should be enabled in the whole program except in this particular snippet of code. This is about fine grained control. Disabling the warning in GCC for the whole program can be achieved by just not passing -pedantic
to the compiler.