Finding "dead code" in a large C++ legacy application [closed]

Solution 1:

You'll want to use a static analysis tool

  • StackOverflow: What open source C++ static analysis tools are available?
  • Wikipedia: List of tools for static code analysis

The main gotcha I've run into is that you have to be careful that any libraries aren't used from somewhere that you don't control/have. If you delete a function from a class that gets used by referencing a library in your project you can break something that you didn't know used the code.

Solution 2:

You can use Cppcheck for this purpose:

$ cppcheck --enable=unusedFunction .
Checking 2380153.c...
1/2 files checked 0% done
Checking main.c...
2/2 files checked 0% done
[2380153.c:1]: (style) The function '2380153' is never used.