为什么在没有其他警告的情况下,仅由g ++标记“ cc1plus:警告:无法识别的命令行选项”作为“ no-”选项?

马克·加勒克
> cat warning.cpp
#pragma foobar
> cat no_warning.cpp
#pragma message "foobar"
> g++ -Wall -Wno-foobar -c warning.cpp
warning.cpp:1:0: warning: ignoring #pragma foobar  [-Wunknown-pragmas]
cc1plus: warning: unrecognized command line option "-Wno-foobar" [enabled by default]
> g++ -Wall -Wno-foobar -c no_warning.cpp
no_warning.cpp:1:17: note: #pragma message: foobar
受雇于俄罗斯

这是设计使然,在这里说明

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.

换句话说,假设您有foo.cc,并且GCC-4.9警告其中有某些东西(我们称它为foobar),但是您相信使用foobar可以安全。

由于您希望将所有警告都视为错误(带有-Werror),因此请忠实地添加-Wno-foobar到中Makefile

现在,其他人尝试使用GCC-4.8构建您的代码。如上所述,这不会产生任何警告,他会成功。

如果确实产生警告,则您将无法同时使用该foobar构造,并且无法使用可同时用于MakefileGCC-4.8和GCC-4.9的单个构造

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档