Apple LLVM 编译器 - 使用编译指示来禁止文件一部分的所有警告?
我需要对我的源文件之一的部分内容发出禁止警告。这就是我所拥有的。它不起作用。
#pragma GCC diagnostic push
#pragma GCC "-w" // also tried "-Wall"
// code that generates warnings here
#pragma GCC diagnostic pop
I need inhibit warnings for part of one of my source files. This is what I have. It's not working.
#pragma GCC diagnostic push
#pragma GCC "-w" // also tried "-Wall"
// code that generates warnings here
#pragma GCC diagnostic pop
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用以下格式禁用单个警告:
除非,这不适用于
"-Wall"
,仅适用于单个警告。我建议仅禁用您遇到的特定警告,并且仅当它位于您无法控制的源文件中时。如果它出现在您的代码中,您应该认真考虑以正确的方式修复警告。编辑:请参阅第 3.8 节,请求或抑制警告的选项,在GCC 文档。
编辑 2:啊,没有意识到这不是一个全面的列表。似乎没有任何文档包含完整的列表,但您可以随时检查源代码。浏览 clang 源代码,它看起来像 include/clang/Basic/DiagnosticGroups.td 列出了一大堆。
You can disable individual warnings using the format:
Except, that doesn't work for
"-Wall"
, only for individual warnings. I would recommend only disabling the particular warning you're experiencing, and only if it's in source files over which you've no control. If it's in your code, you should seriously consider fixing the warnings in the proper way.Edit: See Section 3.8, Options to Request or Suppress Warnings, in the GCC docs.
Edit 2: Ah, didn't realize that isn't a comprehensive list. There doesn't appear to be any documentation containing a comprehensive list, but you can always check the source. Poking around the clang source, it looks like include/clang/Basic/DiagnosticGroups.td lists a whole bunch of them.
如果使用 XCode,您可以转到构建日志并展开编译器输出,它会告诉您在编译指示中使用的警告名称
If using XCode, you can go to the build log and expand the compiler output and it will tell you the warning name to use in the pragma