CodeQL 文档

无用条件语句

ID: cpp/empty-if
Kind: problem
Security severity: 
Severity: recommendation
Precision: high
Tags:
   - reliability
   - readability
Query suites:
   - cpp-security-and-quality.qls

单击以查看 CodeQL 代码库中的查询

此规则查找具有空 then 分支且没有 else 分支的 If 语句。这些语句通常是未实现的骨架代码,应该进行实现,或者是不使用的代码,应该将其删除以避免混淆和误用。

建议

then 分支中可能缺少语句,或者可以重新编写条件中的表达式而不用 If 语句。

示例

//empty then and else branches, will not do anything (other than the check)
if (check(i)) {
}
  • ©GitHub, Inc.
  • 条款
  • 隐私