<分区>
我想抑制零参数的 GCC 可变参数宏参数警告,例如由以下人员生成:
// 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
使用 GCC 5.3.0 时源文件中的特定宏定义。
在 clang 中,这是按如下方式完成的:
// ... 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
在 gcc 中,-pedantic
似乎是一种神奇的警告类型,因此以下内容不起作用:
// ... large file
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
#define FOO(A, ...) foo(A, ##__VA_ARGS__)
#pragma GCC diagnostic pop
// ... large file
需要说明的是,除此特定代码片段外,整个程序都应启用警告。这是关于细粒度控制。只需不将 -pedantic
传递给编译器即可在 GCC 中为整个程序禁用警告。