如何将gcc警告转储为结构化格式
How do I dump gcc warnings into a structured format?
和许多人一样,我用大量的警告标志构建我的项目
由于并非所有警告标志都是有害的,因此编译会变得嘈杂。
诸如"未使用的变量"、"初始化列表中的隐藏成员"、"缺少开关默认值"之类的警告都很重要,但它们在构建过程中会造成太多混乱,很难发现重要的警告。
对于一个大型项目,可能会有成千上万的警告与构建语句混合在一起,尽管之后会进行解析,但这会变得很麻烦。同样不希望在代码中维护编译器杂注和推送/弹出警告。
如何以结构化格式转储编译器警告
不管是不是XML、JSON、YAML、CSV,有没有一种方法可以告诉编译器转储所有发出的警告?这样的格式可以让我更有效地查看警告,并按类型、文件、数量等对其进行排序。
GCC 9增加了[1]对以JSON格式输出警告和错误消息的支持,只需使用-fdiagnostics-format=json
选项。
比较的输出
$ gcc-9 -c cve-2014-1266.c -Wall
cve-2014-1266.c: In function ‘SSLVerifySignedServerKeyExchange’:
cve-2014-1266.c:629:2: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
629 | if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
| ^~
cve-2014-1266.c:631:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
631 | goto fail;
| ^~~~
带有JSON格式的
[
{
"children": [
{
"kind": "note",
"locations": [
{
"caret": {
"column": 3,
"file": "cve-2014-1266.c",
"line": 631
},
"finish": {
"column": 6,
"file": "cve-2014-1266.c",
"line": 631
}
}
],
"message": "...this statement, but the latter is misleadingly indented as if it were guarded by the u2018ifu2019"
}
],
"kind": "warning",
"locations": [
{
"caret": {
"column": 2,
"file": "cve-2014-1266.c",
"line": 629
},
"finish": {
"column": 3,
"file": "cve-2014-1266.c",
"line": 629
}
}
],
"message": "this u2018ifu2019 clause does not guard...",
"option": "-Wmisleading-indentation"
}
]
[1]https://developers.redhat.com/blog/2019/03/08/usability-improvements-in-gcc-9/
- coala项目试图使其包装的工具产生相同的结构化输出格式(请参阅http://wordpress.schuirmann.eu/2016/02/coala-at-fosdem-2016/#comment-123)。遗憾的是,似乎并没有一个现成的"熊"来包装编译器
- 与上面类似的是,爱立信已经构建了一个名为CodeChecker的工具,它可以让你跟踪项目随着时间的推移发出的叮当声静态分析警告
- 有一个奄奄一息的项目叫做firehose,它封装了gcc和几个C静态分析工具的输出
- clang具有
-fdiagnostics-format=msvc
,这可以使其输出稍微更有结构
同时,可以帮助您的是使用-Werror=
将那些您认为关键的编译器警告转化为错误,这样您就会注意到它们在警告的噪音之上破坏了构建。
相关文章:
- 在基于范围的for循环中使用结构化绑定声明
- 使用结构化绑定'Reflection'
- 为什么结构化绑定不使用"auto&"返回对结构成员的引用,而是返回成员本身
- 为什么 boost::comb 对结构化绑定的支持缺少结构化绑定机制对 boost::tuples::cons 的适应?
- 结构化绑定初始值设定项表单 { 赋值表达式 } 对于 clang 上的数组类型失败
- 在 C++14 中手动实现结构化绑定
- 为什么结构化绑定不支持可变数组?
- 为<vtkDataArray> VTK 非结构化网格声明 vtkSmartPointer 类型的变量时出现问题
- 在只读(即 const)访问器上执行结构化绑定的最佳实践是什么?
- 是否有像ADTF2这样的结构化属性?
- 带有 std::minmax 和 rvalues 的结构化绑定
- 在无序映射的结构化绑定中推导类型
- 为什么基于范围的 for 循环中的结构化绑定只是一个副本而不是引用?
- 您自己的类型的结构化绑定,不是结构或元组(通过公共成员函数)
- 共享或私有 openmp 代码中的结构化类型变量
- 结构化绑定:遍历元组的双端面
- 结构化绑定是否适用于 std::vector?
- 结构化绑定,无需复制即可获取子向量的连续元素
- 将Boost序列化文本存档转换为结构化格式
- 如何将gcc警告转储为结构化格式