死代码识别(C ++) [英] Dead code identification (C++)

查看:216
本文介绍了死代码识别(C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大的遗留C ++项目编译在Visual Studio 2008.我知道有一个相当数量的死代码,没有访问任何地方 - 方法,没有被调用,整个类,没有使用。 p>

我正在寻找一个可通过静态分析识别此工具的工具。



此问题:旧版C / C ++项目中的死代码检测建议使用代码覆盖工具。这不是一个选项,因为测试覆盖率只是不够高。



它还提到一个-Wunreachable-code。选项到gcc。我想要类似的Visual Studio。我们已经使用链接器的/ OPT:REF选项来删除冗余代码,但是这不会将死代码报告为有用的级别(当与/ VERBOSE一起使用时,有超过100,000行,包括来自库的很多行)。



有没有更好的选项,可以很好地与Visual Studio项目?

解决方案

您需要遵循QA-C ++的内容( http://www.programmingresearch.com/QACPP_MAIN) .html ),另请参阅 http://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis

您正在寻找用于检测无法访问的代码的静态代码分析工具;许多编码指南(例如MISRA-C ++,如果我没有错误)要求没有不可达的代码存在。专门用于强制执行此类指南的分析工具将是您最好的选择。



您也希望能够找到该工具的其他用途。 p>

I have a large legacy C++ project compiled under Visual Studio 2008. I know there is a reasonably amount of 'dead' code that is not accessed anywhere -- methods that are not called, whole classes that are not used.

I'm looking for a tool that will identify this by static analysis.

This question: Dead code detection in legacy C/C++ project suggests using code coverage tools. This isn't an option as the test coverage just isn't high enough.

It also mentions a -Wunreachable-code. option to gcc. I'd like something similar for Visual Studio. We already use the linker's /OPT:REF option to remove redundant code, but this doesn't report the dead code at a useful level (when used with /VERBOSE there are over 100,000 lines, including a lot from libraries).

Are there any better options that work well with a Visual Studio project?

解决方案

You'll want something along the lines of QA-C++ (http://www.programmingresearch.com/QACPP_MAIN.html), also see http://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis for similar products.

You're looking for a static code analysis tool that detects unreachable code; many coding guidelines (such as MISRA-C++, if I'm not mistaken) require that no unreachable code exists. An analysis tool geared specifically to enforce such a guideline would be your best bet.

And you'll like be able to find other uses for the tool as well.

这篇关于死代码识别(C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆