我正在使用 gcc 7.3。例如,如果我用 int main(){ }
编译
gcc main.c -Wno-foo
,编译成功,没有错误输出。
将源更改为 int main(){ int a[-1];/*uncompilable*/
在维护构建命令的同时让我:
main.c: In function ‘main’:
main.c:3:6: error: size of array ‘a’ is negative
int a[-1];
^
main.c: At top level:
cc1: warning: unrecognized command line option ‘-Wno-foo’
我可以在不向源代码中引入编译错误的情况下强制显示无法识别的命令行选项“-Wno-foo”
警告/错误消息吗?
-Wfoo
(没有 no-
)会立即给我一条警告消息,但我宁愿保留 no-
那里。 (这是为了编译器功能测试,我在构建过程中进行了测试。)
最佳答案
这显然是 gcc 的一个特性,而不是一个错误。来自GCC manual :
When an unrecognized warning option is requested (e.g., '-Wunknown-warning'), GCC emits a diagnostic stating that the option is not recognized. However, if the '-Wno-' form is used, the behavior is slightly different: no diagnostic is produced for '-Wno-unknown-warning' unless other diagnostics are being produced. This allows the use of new '-Wno-' options with old compilers, but if something goes wrong, the compiler warns that an unrecognized option is present.
因此,如果您需要知道该选项是否存在,您需要在没有 no-
的情况下使用它。先做那个;如果您发现它受支持,请执行任何需要 -Wno-foo
参数的测试。
关于c - 从 gcc 引出 "unrecognized command line option",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52577170/