Run static analysis on C++ code with cppcheck.

Run static analysis on C++ code with cppcheck.

cppcheck is a free command line program that will perform static analysis and error checking on C++ code. This is very useful for finding unused variables, uninitialized objects, scope reduction, copy constructor checks and more.


sudo apt-get install cppcheck

Or visit the cppcheck website to build your own from source.


This example will check all source files and look in the given include file for C++ prototypes.

$ cppcheck -v -f --enable=all  -I /to/include/ /to/src/*

Example Output:

File.cpp:176: (style) The scope of the variable 'FILELLI' can be reduced.

Control.hpp:33: (style) 'class Control' does not have a copy constructors recommended since the class contains a pointer to allocated memory.

Class.cpp:21: (style) The function 'CalculateNeuralNetwork' is never used.

Cppcheck is a command-line tool that tries to detect bugs that your C/C++ compiler doesn’t see. It is versatile, and can check non-standard code including various compiler extensions, inline assembly code, etc. Its internal preprocessor can handle includes, macros, and several preprocessor commands. While Cppcheck is highly configurable, you can start using it just by giving it a path to the source code.

Leave a Reply