David Andreoletti
David Andreoletti

Reputation: 4881

How can -Wgnu-zero-variadic-macro-arguments warning be turned off with Clang?

Context

I read Clang's "Controlling Diagnostics via Pragmas" section about turning off particular warnings. It works well in general for all warnings except for -Wgnu-zero-variadic-macro-arguments.

The code is:

MyHeader.hpp

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"

#import "header generating -Wgnu-zero-variadic-macro-arguments warning"

#pragma clang diagnostic pop

Problem

Clang generates -Wgnu-zero-variadic-macro-arguments warnings while compiling translation units importing MyHeader.hpp.

Env

Clang Version: Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn) Target: x86_64-apple-darwin13.4.0 Thread model: posix

OS: Mac OS X 10.9.5

Upvotes: 3

Views: 7744

Answers (3)

madhur4127
madhur4127

Reputation: 336

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

Upvotes: 6

Jeff
Jeff

Reputation: 4229

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

Upvotes: 5

TylerN
TylerN

Reputation: 70

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

Upvotes: 2

Related Questions