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 NameAttribute NameTypeAll Use Count
AddPackageDialog~AddPackageDialogdestr0
AddPackageDialogAddPackageDialogconstr0
EditorDebugStatusChangedvirt0
ModelDatagetBaseType6

Some tool limitations are:

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 NameAttribute NameClass Use CountAll Use Count
ComponentListItemmPathName12
PortionNodemNodeType22

Some limitations are:

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