我想壓制GCC可變參數宏參數警告零個參數,例如通過生產中:如何抑制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時,源文件中的特定宏定義。
在鐺,這是爲完成如下:
// ... 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中的警告。
[零個可變參數宏參數GCC編譯器警告標誌(的可能的複製http://stackoverflow.com/questions/35586426/gcc-compiler -warning-flag-for-zero-variadic-macro-arguments) – Zulan
@Zulan該問題詢問可以禁用此警告的警告標誌的名稱。該問題詢問如何使用該警告標誌在源文件的宏定義中禁用此警告(您的答案在這裏更合適)。 – gnzlbg
我建議只編輯原始問題以闡明你的意圖。 – Zulan