Missing lots of scope types after cppcheck parsing

71 Views Asked by At

We've started using Cppcheck recently and everything is working great except scopes.

I might have misunderstood something but aren't there supposed to be separate scopes for enums, structs, unions etc. in the resulted .dump file after parsing ?

I was expecting there would be based in the cppcheck documentation ("ScopeType" enumerate) and the misra_8_12 rule.

Header file parsed as an example :

enum week {
  LOW = 1,
  MEDIUM,
  HIGH
};

void testfct(void)
{
  enum week day;
}

The only scopes I get as a result are a "global" scope, and a "function" scope for the testfct function. Shouldn't I get a scope for the "week" enum as well ?

My python script for context (with cfg being each file configuration obtained after parsing) :

for scope in cfg.scopes:
  print('    Id:' + scope.Id)
    if scope.className:
      print(' name:' + scope.className)
    if scope.type:
      print(' type:' + scope.type)

The python script doesn't really matter here since the scopes are not even in the .dump xml result file.

And our call to cppcheck (in a .bat file):

cppcheck.exe --enable=all -j 4 --xml --dump <target_file>
1

There are 1 best solutions below

0
Nikeau On

Found the solution.

Turns out you need a C file to include the header where the "enum" is defined. The scopes of enums, struct... are all available in the result .dumb file of the ".c" file but not in the ".h" dumb file, contrary to function scopes that are available in both. I don't really understand the logic behind this, but, here it is.