Good static code analysis tools for C++?

Get answers to all your basic programming questions. No Ogre questions, please!
Post Reply
ethankaminski
Gnoblar
Posts: 15
Joined: Sun Mar 18, 2012 7:42 am
Location: Australia

Good static code analysis tools for C++?

Post by ethankaminski » Wed Mar 21, 2012 9:50 pm

Hey, I'm interested in starting to use static code analysis on my projects, and I wonder if anyone has any recommendations on the matter.

I'm using Linux as my development environment, I intend to stick with commandline tools, I'll probably stick with free (gratis) tools for now, and I prefer free (libre) tools as well. Of course, it may still be useful to mention tools that don't fit that profile, for the sake of others, even if I'm unlikely to use them.

After poking around a bit (and looking at Wikipedia's list), it seems like cppcheck and cpplint are worth trying. cpplint just tries to enforce compatibility with Google's style conventions, which seems potentially useful; whereas cppcheck seems to check for actual code problems that would go unnoticed if left to the compiler. I think I'll have to filter the output of cpplint to ignore conventions that I choose not to follow, and to ignore conventions of Google's that differ from Ogre's. I may also have to filter cppcheck's output if it ends up warning me about Ogre-related code, although hopefully that wouldn't be an issue.

Of course, since I'm using gcc, I should also try compiling with -Wall and -Werror (I've already encountered one release build-only segfault that would've been caught that way!).

Anyway, just wondering if anyone with more experience in the matter has come up with a better solution than what I'm planning.
0 x

User avatar
Jabberwocky
OGRE Moderator
OGRE Moderator
Posts: 2819
Joined: Mon Mar 05, 2007 11:17 pm
Location: Canada
Contact:

Re: Good static code analysis tools for C++?

Post by Jabberwocky » Thu Mar 22, 2012 3:13 am

I've used cppcheck and I recommend it.
There may be some false positives depending on your coding style. But it's worth slogging through all the warnings - you'll likely find many bugs or style issues that should be fixed up.
0 x
Image

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
Contact:

Re: Good static code analysis tools for C++?

Post by masterfalcon » Thu Mar 22, 2012 3:36 am

+1 for cppcheck. I have a big batch of fixes for Ogre from it. Waiting for post 1.8 release though.
0 x

User avatar
saejox
Goblin
Posts: 260
Joined: Tue Oct 25, 2011 1:07 am

Re: Good static code analysis tools for C++?

Post by saejox » Wed Jun 27, 2012 3:06 pm

let me answer this for future reference.
dont just use one tool. they all check for diffrent type of errors.
here are my recommendations

/analyze in VC++
cppcheck
eclipse static analysis (works very good, i am surprised, it found lots of errors /analyze and cppcheck missed)
clang ( setup is a bitch, nevertheless very much worth it)

most paid tools are not even good as cppcheck. i tested many.
0 x
Nimet - Advanced Ogre3D Mesh/dotScene Viewer
asPEEK - Remote Angelscript debugger with html interface
ogreHTML - HTML5 user interfaces in Ogre

nickG
Greenskin
Posts: 122
Joined: Fri Jan 20, 2012 6:44 pm
Location: Russia,Moscow

Re: Good static code analysis tools for C++?

Post by nickG » Thu Aug 02, 2012 8:04 pm

You can use PVS-Studio
0 x

User avatar
Miscreant
Greenskin
Posts: 126
Joined: Mon Jun 14, 2010 2:12 am
Location: Brisbane, Australia

Re: Good static code analysis tools for C++?

Post by Miscreant » Mon Aug 13, 2012 11:29 am

I'll third cppcheck, plus clang is also very good. Clang setup on Windows is a bitch but seemed pretty easy on Linux - just install and substitute "g++" and "gcc" in your project build options for "clang++" and "clang" respectively.
0 x

Andrey_Karpov
Gnoblar
Posts: 3
Joined: Sun Oct 30, 2011 7:17 pm

Re: Good static code analysis tools for C++?

Post by Andrey_Karpov » Wed Jan 08, 2014 4:28 pm

CppCat - new plugin for Visual Studio 2010-2013. CppCat is a lite static code analyzer for C/C++. Visual Studio gallery: http://bit.ly/1acLXh0
0 x

James_Carter
Gnoblar
Posts: 1
Joined: Sun Oct 12, 2014 7:18 pm

Re: Good static code analysis tools for C++?

Post by James_Carter » Sun Oct 12, 2014 7:21 pm

You can test CppDepend, it's free for the open source community. and it integrate also cppcheck tool.
0 x

Post Reply