Finding "dead code" in a large C++ legacy application

gudnithor picture gudnithor · Mar 4, 2010 · Viewed 27.7k times · Source

I'm currently working on a large and old C++ application that has had many developers before me. There is a lot of "dead code" in the project, classes and functions that aren't used by anyone anymore.

What tools are available for C++ to make a analysis of large code base to detect and refactor dead code? Note: I'm not talking about test coverage tool like gcov.

How do you find dead code in your project?

Answer

Alan Jackson picture Alan Jackson · Mar 4, 2010

You'll want to use a static analysis tool

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.