linux-在旧版gcc上使用-Wno-implicit-fallthrough

我有一个在gcc 4.8.4下可以正常构建的项目.我尝试使用gcc 7进行构建,并注意到很多-Wimplicit-fallthrough =警告. As far as I’m aware,这确实是在gcc版本7中添加的.我现在在构建时使用-Wno-implicit-fallthrough来禁止显示这些警告.回到gcc的旧版本,保留-Wno-implicit-fallthrough编译器标志不会导致任何错误,即使我不相信gcc 4可以识别此选项.怎么会?特别是-Wno-选项是否被允许不被识别?
最佳答案
来自man gcc:

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.

总结一下:如果一切顺利,将忽略未知的-Wno- *开关以保持兼容性.

转载注明原文:linux-在旧版gcc上使用-Wno-implicit-fallthrough - 代码日志