Automated analysis is the main advantage to working with a modern statically typed compiled language like C++.
All reasonable warning levels should be enabled.
A good combination of settings is -Wall -Wextra -Wshadow -Wnon-virtual-dtor -pedantic
-Wall -Wextra
: reasonable and standard-Wshadow
: warn the user if a variable declaration shadows another with the same name in the same scope-Wnon-virtual-dtor
: warn the user if a class with virtual functions has a non-virtual destructor. This can lead to hard to track down memory errors-pedantic
: warn about non-portable code, C++ that uses language extensions.
MSVC has fewer warning options, so all warnings should be enabled: /W4
. /Wall
could be considered, but does not seem to be recommended even by microsoft.
Static analyzers look for errors that compilers do not look for, such as potential performance and memory issues.
Cppcheck is free and opensource. It strives for 0 false positives and does a good job at it. Therefor all warning should be enabled: -enable=all
Clang's analyzer's default options are good for the respective platform. It can be used directly from cmake.
Can be enabled with the /analyze
command line option. For now we will stick with the default options.
A coverage analysis tools shall be run when tests are executed to make sure the entire application is being tested. Unfortunately, coverage analysis requires that compiler optimizations be disabled. This can result in significantly longer test execution times.
The most likely candidate for a coverage visualization is the lcov project. A secondary option is coveralls, which is free for open source projects.
If it is determined by team consensus that the compiler or analyzer is warning on something that is either incorrect or unavoidable, the team will disable the specific error to as localized part of the code as possible.
Very nice and detailed, thank you.