g++ - 如何通过几行代码禁用 g++ 中的所有警告

标签 g++ warnings gcc-warning

如何在几行代码上禁用所有警告。 可以使用 GCC 诊断功能禁用特定警告,但是否有针对所有警告的标志。 我尝试了这个方法,但不起作用

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-wall"
// some code
#pragma GCC diagnostic pop

最佳答案

从这里:http://dbp-consulting.com/tutorials/SuppressingGCCWarnings.html

对于 4.6 或更高版本,您可以保存用户诊断标志的状态。您可以将其插入到导致虚假警告的行周围:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
    // Code that causes warning goes here
#pragma GCC diagnostic pop

为了实现所需的行为,您应该使用“-Wall”而不是“-Wdeprecated-declarations”(而不是“-wall”——注意大写的“W”)。

关于g++ - 如何通过几行代码禁用 g++ 中的所有警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6407298/

相关文章:

c - gcc 警告 : braces around scalar initializer

c++ - VSCode c++ task.json包含路径和库

java - g++: 找不到文件

c++ - 使用 g++ : 'malloc' was not declared in this scope 时出错

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

c++ - GCC 误导性缩进警告从此时起被禁用?

c++ - 对显式实例化模板函数的 undefined reference

xcode - 自更新到 macOS High Sierra 以来,Xcode 中出现“FIFinderSyncExtensionHost 类已在两者中实现”警告

python - Django 中的详细弃用警告

c - -Wmissing-field-initializers 何时触发警告?