CppCheck is open source and cross-platform.
Mac OSX:
brew install cppcheck
ID : 10136
viewed : 38
Tags : c++coding-stylestatic-analysisc++
96
88
Concerning the GNU compiler, gcc has already a builtin option that enables additional warning to those of -Wall. The option is -Weffc++ and it's about the violations of some guidelines of Scott Meyers published in his books "Effective and More Effective C++".
In particular the option detects the following items:
79
Under development for now, but clang does C analysis and is targeted to handle C++ over time. It's part of the LLVM project.
Update: While the landing page says "The analyzer is a continuous work-in-progress", it is nevertheless now documented as a static analyzer for both C and C++.
Question: How can I run GCC/Clang for static analysis? (warnings only)
Compiler option: -fsyntax-only
60
Oink is a tool built on top of the Elsa C++ front-end. Mozilla's Pork is a fork of Elsa/Oink.
54
Someone else mentioned -Weffc++, but that is actually one of the only GCC warnings I do not turn on by default. However, the set of warnings that I do turn on is the most important static analysis tool in my kit. You can see the complete list of recommended warnings.
In summary:
-pedantic -Wall -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default -Wundef -Werror -Wno-unused
Note that some of these require a new version of gcc, so you may need to eliminate them from your list if you are stuck back on 4.5 or something.