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

标签 linux gcc suppress-warnings gcc-warning fall-through

我有一个在 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/

相关文章:

java - 如何从磁盘复制特定文件

linux - 什么时候使用 .fini_array 部分?

g++ - gcc 警告" 'will be initialized after'

c++ - 意外的 fork 行为

linux - 期待 : How to create a remote directory thru ssh command

gcc - set_c0_status()函数在哪里定义的?

c - GCC 不工作但 G++ 可以

c++ - 为什么这个 C++ 代码在不同的编译器上给出不同的输出?

c++ - 如何在MSVC中禁止所有第三方编译时间警告

c++ - Bool 永远不会为 NULL [-Waddress]