You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

clang-13的scan-build静态分析未检出预期错误,操作哪里有误?

问题原因

  • 启用的检查器覆盖范围不足
    你当前仅开启了alpha.core.BoolAssignment单检查器,构造、析构函数中调用虚函数的告警属于alpha.cplusplus.VirtualCall检查器的检测范围,未开启的情况下无法检出对应问题。
  • alpha.core.BoolAssignment检查器触发条件不匹配当前用例
    该检查器默认仅对非0/1的整型常量表达式赋值给bool类型的场景告警,你示例代码中的a、b都是普通局部变量,不属于常量表达式,因此无法触发检查。如果你将变量声明为const int a=5、const short b=4,即可触发该类告警。

修正后的分析命令

你可以使用以下命令覆盖你预期的两类检测场景:

scan-build -enable-checker alpha.core.BoolAssignment -enable-checker alpha.cplusplus.VirtualCall clang++ a5.cpp

如果需要alpha.core.BoolAssignment对非常量的整型赋值给bool的场景也输出告警,可以额外添加分析配置参数:

scan-build -enable-checker alpha.core.BoolAssignment -enable-checker alpha.cplusplus.VirtualCall -analyzer-config alpha.core.BoolAssignment:WarnOnNonConstant=true clang++ a5.cpp

内容的提问来源于stack exchange,提问作者kratos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 14:48:03