简体   繁体   English

Apple LLVM 编译器——使用编译指示来禁止对文件的一部分发出所有警告?

[英]Apple LLVM compiler — use pragmas to inhibit all warnings for a portion of a file?

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

You can disable individual warnings using the format:您可以使用以下格式禁用单个警告:

#pragma GCC diagnostic ignored "-Wwarning-to-disable"

Except, that doesn't work for "-Wall" , only for individual warnings.除了,这不适用于"-Wall" ,仅适用于个别警告。 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 .编辑:请参阅GCC 文档中的第 3.8 节,请求或抑制警告的选项

Edit 2: Ah, didn't realize that isn't a comprehensive list.编辑 2:啊,没有意识到这不是一个完整的列表。 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.查看 clang 源代码,看起来include/clang/Basic/DiagnosticGroups.td列出了一大堆。

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如果使用 XCode,您可以 go 到构建日志并展开编译器 output,它会告诉您在 pragma 中使用的警告名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM