views:

135

answers:

2

I have worked with java for a while now, and I found checkstyle to be very useful. I am starting to work with c++ and I was wondering if there is a style checker with similar functionality. I am mainly looking for the ability to write customized checks.

+1  A: 

I have had good feedback about Artistic Style which allows to apply a uniform style on code without too much hassle.

It's free and there are plenty of "classic" styles already defined. It might not work with C++0x new constructs though.

I am also expecting a Clang library, though I haven't found any to date. Normally, given Clang's structure it should be relatively easy, but then it's always easier to say than to code and I guess nobody took the time yet.

Matthieu M.
AStyle is more of a beautifier and you cannot use it to actually check style violations as you can use checkstyle for Java.
celavek
I am actually looking for a style checker rather than a formatter. I would like to be able to create checks for my teams style conventions, and then run the checker to see if everyone following the conventions.
@megamug: but what's the point of having a "checker" report if something has been done right or not, when you could simply have a formatter pass in your makefiles to automatically make it right without humane intervention ?
Matthieu M.
@Matthieu - Typically there is a process involved in changing existing code, meaning someone has to make sure that it still works the way that it did before. There is no process necessary for analyzing code.
@megamug: Ah... didn't worry much about testing to be fair, we have continuous integration where I work so any change that would break tests would be rejected anyway.
Matthieu M.
+2  A: 

What about Vera++ ?

Vera++ is a programmable tool for verification, analysis and transformation of C++ source code. Vera++ is mainly an engine that parses C++ source files and presents the result of this parsing to scripts in the form of various collections - the scripts are actually performing the requested tasks.

Click here to see a more complete demo of what it can do.

crc.hpp:157: keyword 'explicit' not followed by a single space
crc.hpp:588: closing curly bracket not in the same line or column
dynamic_property_map.hpp:82: keyword 'if' not followed by a single space
functional.hpp:106: line is longer than 100 characters
multi_index_container.hpp:472: comma should be followed by whitespace
version.hpp:37: too many consecutive empty lines
weak_ptr.hpp:108: keyword 'catch' not followed by a single space
...
karlphillip
That looks promising, I will have to play around with it a bit.