Is there a list of Cppcheck messages?
Asked Answered
C

1

21

Our team previously used Lint as a static code analyser, but it became too cluttered and had too much noise.

We are using C++03 with frequent use of Boost, and Lint didn't seem to like Boost (I hear this has become better in later versions). I started looking at other static code analysers and came across Cppcheck and tried it out. I'm very impressed at what it warns about (I've seen about a dozen informationals and style problems).

What I'm interested in is: Is there are a list of all Cppcheck messages that Cppcheck issues, similar to how Lint and PVS-Studio both have a list of their messages? The official Cppcheck website lists:

  • Out of bounds checking
  • Memory leaks checking
  • Detect possible null pointer dereferences
  • Check for uninitialized variables
  • Check for invalid usage of STL
  • Checking exception safety
  • Warn if obsolete or unsafe functions are used
  • Warn about unused or redundant code
  • Detect various suspicious code indicating bugs

But I'm more interested in something similar to Lint and PVS-Studio, and similar to how the results are displayed in Visual Studio:

ID | Category/Severity | Text
Caretaker answered 23/7, 2015 at 4:29 Comment(0)
E
22

A list of Cppcheck checks is available at the project's wiki, and as stated there, you can also get the list from the command-line by running:

$ cppcheck --doc

or

$ cppcheck --errorlist

The errorlist outputs an XML file with all three things you want. Here's a small example from it:

<error id="unnecessaryForwardDeclaration" severity="style" msg="The variable &apos;name&apos; forward declaration is unnecessary. Type variable is already declared earlier."/>
<error id="variableHidingEnum" severity="style" msg="variable &apos;name&apos; hides enumerator with same name"/>
<error id="unnecessaryQualification" severity="style" msg="The extra qualification &apos;type&apos; is unnecessary and is considered an error by many compilers."/>

To save the output to a file rather than the command window, use:

cppcheck --errorlist > errorlist.xml
Epigynous answered 23/7, 2015 at 18:56 Comment(2)
I like that there's a list, I hate that it's in pure XML and nigh unreadable with all the &apos; in it.Bequeath
@Bequeath It's possible to reprocess with xmlstarlet: cppcheck --errorlist | xmlstarlet sel -t -m "//error" -v "@id" -o ": " -v "@msg" -n | xmlstarlet unescEpigynous

© 2022 - 2024 — McMap. All rights reserved.