Cppcheck thinks I have "redundant code: a statement found starting with a numeric constant"

Cppcheck (version 1.46.1) gives the following warning for an enumeration like this:

enum DATABASE_TYPE { DATABASE_TYPE_UNKNOWN = -1, // <- line of warning DATABASE_TYPE_ORACLE, DATABASE_TYPE_MSACCESS }; 

Backup code: statement found that starts with a numeric constant

I do not think that he is superfluous. It is very important to be able to do such things.

Is this a cppcheck error or am I not seeing anything?

Update

I managed to weld it to a minimal example. This was complicated by cppcheck, having 2 (later) errors, which made it look as if my abbreviations were not affected.
There are 5 files: ah , a.cpp , bh , b.cpp and inc.h with the following contents.
VC9 compiles it without warning (warning level 4).

 // ah #pragma once #include "inc.h" // a.cpp #include "ah" #include "bh" int main() { return 0; } // bh #pragma once #include "inc.h" // b.cpp #include "bh" //inc.h #pragma once enum MY_ENUM_TYPE { INVALID_VALUE = -1, FIRST_VALUE, SECOND_VALUE }; 

So, I'm pretty sure this is a cppcheck error. Any divergent opinions?

+7
source share
2 answers

I suppose that:

A) invalid somehow declared or defined elsewhere.

B) The listing is defined in the header included twice (without title protection). Because you get the same error for this code:

 enum SomeEnumType { invalid = -1, first, second, }; enum SomeEnumType { invalid = -1, // <- line of warning first, second, }; 

Is your code compiled with GCC?


UPDATE:

Yes, this seems like a cppcheck error - #pragma once does not work. If you replace it with a wrapper #ifndef A_H / #define A_H / #endif , cppcheck will no longer complain.

This also looks like a recognized problem .

+6
source

enumerations are of the data type as unsigned integers.

Update: it looks like the implementation is implemented: Are C ++ subscribers signed or not?

-2
source

All Articles