Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a list of Cppcheck messages?

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
like image 776
Tas Avatar asked Jul 23 '15 04:07

Tas


People also ask

How do I turn off Cppcheck warning?

According to the cppcheck help: The error id is the id that you want to suppress. The easiest way to get it is to use the --xml command line flag. Copy and paste the id string from the xml output.

How do I open a Cppcheck file?

Cppcheck is automatically run on open files. To select the files to check in the currently active project, select Analyze > Cppcheck.


1 Answers

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."/>
like image 192
HairyFotr Avatar answered Sep 28 '22 08:09

HairyFotr