How can -Wgnu-zero-variadic-macro-arguments warning be turned off with Clang?
This seems to be working in Xcode 6.4 (6E35b). The pragma suppresses the warning now.
I have -Weverything
in build settings. Without the diagnostic ignore I definitely get the warning:
Token pasting of ',' and __VA_ARGS__ is a GNU extension
Output from Terminal to match your Env section:
$ clang --version
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.4.0
Thread model: posix
Using the following code:
#define DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#import "Macros.h"
#pragma clang diagnostic pop
In which Macros.h contains:
#ifdef DEBUG
#define AssLog(condition, message, ...) NSAssert(condition, message, ##__VA_ARGS__)
#else
#define AssLog(condition, message, ...) if (!condition) NSLog((@"%@ [Line %d] " message), [NSString stringWithUTF8String:__PRETTY_FUNCTION__], __LINE__, ##__VA_ARGS__)
#endif
Since this answer is the top result for clang's error:
Token pasting of ',' and VA_ARGS is a GNU extension
C++20 doesn't require the token pasting operator (##__VA_ARGS__
) and regular __VA_ARGS__
will work.
see example here
The accepted answer works well for this specific issue, but if you are trying to actually kill the warning rather than hiding it, you can compile with -std=gnu++11
or -std=gnu++1y
or whatever the relevant gnu compliant standard would be for your code base. I was having this same warning and it took some digging to realize what it was trying to tell me. This is for CLang++ but there should be a GCC equivalent.
Relevant Warning
Token pasting of ',' and VA_ARGS is a GNU extension
Env
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.3.0
Thread model: posix