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.
-
What would be an example of a style violation? "Style" to my mind is entirely code formatting, but your comments below indicate that's not what you mean... – Billy ONeal Sep 08 '10 at 13:47
-
It is not that I don't want formatting as a part of it. I just want to know whether the formatting is correct. Also, I have used it for variable naming conventions – Megamug Sep 08 '10 at 13:54
-
I think the eclipse CDT plugin will do some of what you want – Falmarri Sep 08 '10 at 17:50
-
A mandatory link: [SO: A free tool to check C/C++ source code against a set of coding standards](http://stackoverflow.com/questions/93260/a-free-tool-to-check-c-c-source-code-against-a-set-of-coding-standards) – Ilia K. Dec 23 '12 at 14:32
3 Answers
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
...

- 92,053
- 36
- 243
- 426
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.

- 287,565
- 48
- 449
- 722
-
AStyle is more of a beautifier and you cannot use it to actually check style violations as you can use checkstyle for Java. – celavek Sep 08 '10 at 13:30
-
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 Sep 08 '10 at 13:34
-
@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. Sep 08 '10 at 13:52
-
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 Sep 08 '10 at 14:06
-
@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. Sep 08 '10 at 14:50