c++visual-studiocode-analysisdead-code

Find out which code is never called in C++ project in Visual Studio 2012


I am using VS2012 and I would like to know which code in my project is never called. How can I do it?

Here is the menu I tried out for the dead code analysis, but did not find it here.

enter image description here


Solution

  • Short answer: Visual Studio does not support this1.

    The code analysis checkers that can find uncalled functions are available for managed (i.e. .NET) code only, e.g. CA1811: Avoid uncalled private code.

    Static analysis of C++ code is a lot more difficult, and there are only a handful of Code Analysis for C/C++ Warnings related to unused/redundant/unreachable code:

    All of those rules indicate either a bug, or point to redundant code, that is never executed. The list applies to code analysis rules implemented in Visual Studio 2017. Previous versions of Visual Studio may not provide checkers for all of them.


    1 This is true up to and including Visual Studio 2017, the most current release at the time of writing.