152

It looks quite easy to find such a tool for Java (Checkstyle, JCSC), but I can't seem to find one for C/C++. I am not looking for a lint-like static code analyzer, I only would like to check against coding standards like variable naming, capitalization, spacing, identation, bracket placement, and so on.

Serge
  • 7,508
  • 5
  • 37
  • 45
Drealmer
  • 5,268
  • 3
  • 27
  • 36
  • 3
    If you don't find the answer you want here, consider this question: http://stackoverflow.com/q/10819398/120163 – Ira Baxter May 30 '12 at 19:42

12 Answers12

57

The only tool I know is Vera. Haven't used it, though, so can't comment how viable it is. Demo looks promising.

ΦXocę 웃 Пepeúpa ツ
  • 43,054
  • 16
  • 58
  • 83
yrp
  • 4,397
  • 1
  • 22
  • 10
  • I have tested it, and it is quite simple. But it works! – Jader Dias May 31 '11 at 18:47
  • 7
    I tried it but was disappointed. It tokenised C++ code but has only a single token type for "identifiers", so it doesn't differentiate between say class names, member variables and local variables. There is therefore no way I could find to enforce different naming conventions to different types of identifier. – John W Aug 31 '11 at 06:56
  • Vera does not have a very comprehensive set of rules - but they are extendable (in TCL) – fmuecke Oct 08 '11 at 07:00
  • 2
    "Extensible" only for very simple tasks. Since Vera's understanding of C++ is shallow, any "deep style check" (consider a possible [I'm not suggesting good] rule: for every allocation, there's a corresponding deallocation in the same function) will have to encode the appropriate C++ knowledge, and that is *really really* hard, which means it won't happen. – Ira Baxter May 30 '12 at 19:38
  • Fixed link to Vera: https://bitbucket.org/verateam/vera – congusbongus May 20 '13 at 00:56
  • I just gave it a quick try: It gave up parsing entirely upon encountering something seemingly trivial as a one-line comment that followed the closing bracket of a namespace declaration. It said I should "fix" it or exclude file... – foraidt Jul 10 '14 at 06:12
  • Vera is incredibly impossible to build from scratch, which you have to do if you're using a CI system and don't want to use TCL. I'll pass. – Qix - MONICA WAS MISTREATED Oct 23 '16 at 00:08
49

Google c++lint from Google code style guide.

schoetbi
  • 9,843
  • 7
  • 44
  • 70
janesconference
  • 6,045
  • 7
  • 52
  • 71
  • 4
    +1. This is very nice - though it does have a very strict style. Not that easy to extend with own rules like with vera++. – fmuecke Oct 08 '11 at 07:04
  • Great if you're using Google's C++ style though :) +1 – jkp Jan 04 '12 at 11:49
  • 3
    I assume this is now whats called *cpplint* It can be found at https://github.com/google/styleguide/tree/gh-pages/cpplint , the link above to c++lint is broken. – Zitrax Dec 09 '15 at 15:30
  • Just for reference, to install, you can use "pip install cpplint". Then you can just use "cpplint file.cpp" or "cpplint --recursive ." instead of "./cpplint.py" which is much preferable IMO. Easier than downloading through github at least – Colin D Sep 22 '16 at 02:37
  • 2
    [Why Google Style Guide for C++ is a deal-breaker](https://www.linkedin.com/pulse/20140503193653-3046051-why-google-style-guide-for-c-is-a-deal-breaker) – phuclv Nov 23 '16 at 15:23
  • I'd really add a word about the downsides of Googles style guide for C++, maybe a link to the interesting article @LưuVĩnhPhúc mentioned. For me, the most important question is if the tool can be easily modified to conform to different stale guides? – Wolf Nov 27 '17 at 15:55
8

I'm sure this could help to some degree cxx checker. Also this tool seems to be pretty good KWStyle It's from Kitware, the guys who develop Cmake.

Andy Lester
  • 81,480
  • 12
  • 93
  • 144
tatsuhirosatou
  • 22,689
  • 14
  • 37
  • 38
7

Not exactly what you ask for, but I've found it easier to just all agree on a coding standard astyle can generate and then automate the process.

Pieter
  • 16,523
  • 6
  • 47
  • 87
  • 1
    You better make clear that **ArtisticStyle focuses solely on formatting** which of course is not a bad thing :) – Wolf Nov 27 '17 at 16:04
6

Try nsiqcppstyle. It's a Python based coding style checker for C/C++. It's easy to extend to add your own rules.

Joshua
  • 123
  • 1
  • 5
4

There's a list. There is also a putative C++ frontend on splint.

EfForEffort
  • 55,496
  • 4
  • 33
  • 39
2

Check universalindentgui on sourceforge.net.

it has many style checkers for C and you can customise the checkers.

Mateusz Piotrowski
  • 6,087
  • 9
  • 44
  • 71
  • [UniversalIndentGUI](http://universalindent.sourceforge.net/) It has a live preview function, can export config and export script. It's great for trying out different "indenters", such as GNU Indent, Artistic Style and Uncrustify. – congusbongus May 20 '13 at 04:21
2

I have used a tool in my work its LDRA tool suite

It is used for testing the c/c++ code but it also can check against coding standards such as MISRA etc.

udpsunil
  • 1,273
  • 2
  • 15
  • 28
  • 1
    Why is this down modded? Even if LDRA is also a static analyzer - something the question is not looking for - I believe it's also capable to check the code for violations of a coding standard. – Vitor Py Jul 15 '10 at 21:58
  • 6
    LDRA costs about as much as your average car... not my idea of free. – Lundin Jul 02 '15 at 14:27
1

Check Metrix++ http://metrixplusplus.sourceforge.net/. It may require some extensions which are specific for your needs.

Andrew
  • 1,430
  • 1
  • 14
  • 25
1

There is cppcheck which is supported also by Hudson via the plugin of the same name.

Wernight
  • 32,087
  • 22
  • 110
  • 128
  • 4
    cppcheck is a static analysis tool and not what the question is looking for. – Vitor Py Jul 15 '10 at 21:59
  • Maybe this changed since 2010: Today Cppcheck also includes warnings for stylistic issues. But, well, the OP explicitly excluded static code analyzers. – Wolf Nov 27 '17 at 16:11
0

Check out Abraxas Code Check http://www.abxsoft.com/codchk_user.html

Tim Child
  • 2,836
  • 1
  • 22
  • 25
  • besides the documentation, it's **not free**: http://www.abxsoft.com/codchk.htm Plus, it seems to be outdated http://www.abxsoft.com/pricing.htm – Wolf Nov 27 '17 at 16:15
-1

I'm currently working on a project with another project to write just such a tool. I looked at other static code analysis tools and decided that I could do better.

Unfortunately, the project is not yet ready to be used without fairly intimate knowledge of the code (read: it's buggy as all hell). However, we're moving fairly quickly, and hope to have a beta release within the next 8 weeks.

The project is open source - you can visit the project page, and if you want to get involved, we'd love some more external input.

I won't bore you with the details - you can visit the project page for that, but I will say one thing: Most static code analysis tools are aimed at checking your code for mistakes, and not very concerned with checking for coding guidelines. We have taken a more flexible approach that allows us to write plugiins to check for both "house rules" as well as possible bugs.

If you want any more information, please don't hesitate to contact me.

Cheers,

Thomi
  • 11,159
  • 9
  • 67
  • 109