1 Star 0 Fork 0

any3ite/codeql

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
DeadCodeFunction.ql 1.00 KB
一键复制 编辑 原始数据 按行查看 历史
Geoffrey White 提交于 2019-04-17 21:17 +08:00 . CPP: Autoformat 'Critical'.
/**
* @name Function is never called
* @description Unused functions may increase object size, decrease readability, and create the possibility of misuse.
* @kind problem
* @id cpp/dead-code-function
* @problem.severity warning
* @tags maintainability
* external/cwe/cwe-561
*/
import cpp
predicate limitedScope(Function f) {
f.isStatic() and not f instanceof MemberFunction
or
f.(MemberFunction).isPrivate()
}
predicate uncalled(Function f) {
limitedScope(f) and
not exists(Function g | g = f or g = f.(VirtualFunction).getAnOverriddenFunction+() |
exists(g.getACallToThisFunction()) or
exists(FunctionAccess fa | fa.getTarget() = g)
)
}
from Function f
where
uncalled(f) and
forall(Function instance | f.(TemplateFunction).getAnInstantiation() = instance |
uncalled(instance)
) and
// tweaks for good results:
exists(f.getBlock()) and
not (f instanceof Constructor or f instanceof Destructor or f.hasName("operator="))
select f, "Dead Code: this function is never called."
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/any3ite/codeql.git
git@gitee.com:any3ite/codeql.git
any3ite
codeql
codeql
main

搜索帮助