Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: tools to statically analyze code (and/or preprocess it) [closed]

Often I could use some tools to statically analyze my code in order to help me making it cleaner. Something like compiler warnings, but those are not enough. Every now and then I dream about writing one (using clang libraries or gccxml), but I guess it would take too much work.

Some things that pop to my mind are:

  1. looking for magic numbers (ie: hardcoded constant numbers different from 0).

  2. checking that the rule of three is always respected (each class must have defined either all of destructor, copy-constructor and assignment operator, or none of them).


I also dream (but these things are pure utopia) about a preprocessor which parses some non-standard code and translates it to valid C++ code, a tool able to:

  1. expand template aliases, so that I can have them in C++ (well, with C++0x this is no longer needed)

  2. move inline functions at the end of files, so that I don't have to respect the declare-before-use rule, and am able to write classes inline as in Java.

  3. offer an extended syntax, like supporting custom operators (which will be expanded in function calls), or some ad-hoc syntax/keyword to implement easily some patterns.


Is there any tool out there, able to do a subset of these things?

Otherwise what libraries would you suggest to implement these tasks (clang libs, gccxml, ...), and how much work do you think it would take?

like image 591
peoro Avatar asked Nov 13 '10 17:11

peoro


2 Answers

cppcheck is just wonderful.

like image 163
Johan Kotlinski Avatar answered Oct 05 '22 08:10

Johan Kotlinski


Google has an interesting tool along with its style guide... called cpplint. It may be helpful for generating cleaner code. Have a look.

http://code.google.com/p/google-styleguide/source/browse/trunk/cpplint/cpplint.py?r=15

like image 44
Natansh Avatar answered Oct 05 '22 08:10

Natansh