我有一个在 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`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49593240/