1

I have a big project with much dead code (big amount of unreferenced functions)

How can I detect functions in a class that are not used?

P.S.: The project uses C++ space, please don't offer ReSharper or .NET addons like this.

Drew Dormann
  • 59,987
  • 13
  • 123
  • 180
user3000633
  • 137
  • 7
  • There is a find all references button in visual studio, but it misses a few things sometimes (especially if you have macros or templates). Visual Assist works better, but it's expensive. In any case, if you have virtual functions no-one will be able to tell if they are actually called by just looking at the code. – Jerem Aug 13 '15 at 06:59

2 Answers2

3
  1. I found this documentation for Microsoft Visual Studio 2015 Link. Maybe the linker can help you with that (You can use the /VERBOSE option to see the functions that are removed by /OPT:REF and the functions that are folded by /OPT:ICF.).

Controls the optimizations that LINK performs during a build.

/OPT:{REF | NOREF}

REF | NOREF /OPT:REF eliminates functions and data that are never referenced; /OPT:NOREF keeps functions and data that are never referenced. When /OFT:REF is enabled, LINK removes unreferenced packaged functions and data. An object contains packaged functions and data (COMDATs) if it was compiled by using the /Gy option. This optimization is known as transitive COMDAT elimination. By default, /OPT:REF is enabled in non-debug builds. To override this default and keep unreferenced COMDATs in the program, specify /OPT:NOREF. You can use the /INCLUDE option to override the removal of a specific symbol. When /OPT:REF is enabled either explicitly or by default, a limited form of /OPT:ICF is enabled that only folds identical functions. If you want /OPT:REF but not /OPT:ICF, you must specify either /OPT:REF,NOICF or /OPT:NOICF. If /DEBUG is specified, the default for /OPT is NOREF, and all functions are preserved in the image. To override this default and optimize a debugging build, specify /OPT:REF. Because /OPT:REF implies /OPT:ICF, we recommend that you also specify /OPT:NOICF to preserve identical functions in debugging builds. This makes it easier to read stack traces and set breakpoints in functions that would otherwise be folded together. The /OPT:REF option disables incremental linking. You have to explicitly mark const data as a COMDAT; use __declspec(selectany). Specifying /OPT:ICF does not enable the /OPT:REF option.

  1. Check this link, maybe it will help too. The main recommendation there is to use external tools for static analysis or code coverage.
Community
  • 1
  • 1
Alex Lop.
  • 6,810
  • 1
  • 26
  • 45
0

15 seconds of googling gave me this:

Link

In the build menu select run code analysis on your YourProjectName. In the output window you should see a warning like this for unused sub routines

Kieren Pearson
  • 416
  • 3
  • 15