Reputation: 3
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.
Upvotes: 0
Views: 2448
Reputation: 380
On Visual Studio 2019 or later:
/OPT:REF
on the linker (removal of unused functions)/VERBOSE:REF
on the linker (enable verbose output for above pass)This will result in such a list:
…
Discarded "public: int * __cdecl OS::Region::tryToReserve<int>(unsigned __int64,struct Supervisor const *)" from allocator.cpp.o
Discarded "public: float * __cdecl OS::Region::tryToReserve<float>(unsigned __int64,struct Supervisor const *)" from allocator.cpp.o
…
Note that the list will be quite long because it lists template instantiations instead of declarations, contains unwind information, imports from 3rd-party libraries, etc.
But it is a starting point.
Upvotes: 2
Reputation: 51364
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.
Upvotes: 3