Oovcde Index
Detecting Dead C++ Code
Oovcde has both static (compile-time) and dynamic (run-time) dead code detection.
Static Dead Code Detection
Oovcde uses CLang to parse C++ files. It finds all methods and functions,
and determines with a call graph which functions are not called by another
function. It outputs a table of the number of times each method or function
is called. The table is viewable in a brower, and is also output as XML.
Typical output looks like the following:
See the output directory for the text file output.
The all usage count is the count of usage by all other methods.
Class Name | Attribute Name | Type | All Use Count |
AddPackageDialog | ~AddPackageDialog | destr | 0 |
AddPackageDialog | AddPackageDialog | constr | 0 |
Editor | DebugStatusChanged | virt | 0 |
ModelData | getBaseType | | 6 |
Some tool limitations are:
- Implicit calls to constructors and destructors or assignment operators
are shown as being unreferenced.
- It is not possible to find out which virtual function is called, so they
are displayed as being unreferenced
-
Multiple functions with the same name can exist in a project when they
are used to build different components. Only one of them is used as the
definition of the function, and the other called functions from the
duplicately named functions will show up as being unreferenced.
The tool can handle methods with the same name as long as they have unique
signatures or are in different namespaces.
These issues only cause the problem that too many functions
are listed as dead code, and therefore the tool is still useful
for identifying true dead code.
Unused Members Detection
Members can be accessed within the class, from other classes or functions.
They can also be accessed as a data member or to access a method of the
data member.
Typical output looks like the following:
See the output directory for the text file output.
The class usage count is the count of the number of methods in the same
class that refer to the attribute.
Class Name | Attribute Name | Class Use Count | All Use Count |
ComponentListItem | mPathName | 1 | 2 |
PortionNode | mNodeType | 2 | 2 |
Some limitations are:
- Classes with the same name used in different components within
the project may list as having unused members.
The tool was run on the Oovcde project, and found many instances of dead
code. This was a bit of a surprise since the project is written by a
single author and the project has only about 40K lines of code.
Dynamic Dead Code Detection
Oovcde has a code coverage tool that is also built using CLang.
It requires extensive tests written for the target project in order
to be able to identify which code is not used. The description
of the coverage tool is here. TestCoverage.html