What open source C++ static analysis tools are available?
CppCheck is open source and cross-platform.
Mac OSX:
brew install cppcheck
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:
- Define a copy constructor and an assignment operator for classes with dynamically allocated memory.
- Prefer initialization to assignment in constructors.
- Make destructors virtual in base classes.
- Have "operator=" return a reference to *this.
- Don’t try to return a reference when you must return an object.
- Distinguish between prefix and postfix forms of increment and decrement operators.
- Never overload "&&", "||", or ",".
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