Add dead code warning of C code to Visual Studio 2022

piutty 1 Reputation point
2022-12-21T13:48:45.853+00:00

I use Visual Studio 2022 to build my C project and OpenCppCoverage to check the coverage.

With these tools, I don't find how to find C functions (static & public) that aren't called. The /Zi option may not produce a PDB with the uncalled function and OpenCppCoverage is unable to detect it:

272935-image.png

As the goal is to detect dead code, one option is to add a warning to visual studio 2022 compilator or linker to raise an error in case of unused function as gcc or to produce a PDB that contain information about the uncalled function (The second option may not work).

Anyone have an idea to detect dead code with these tools?

Developer technologies | C++
Developer technologies | C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other
A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.