CppCheck complains about METHOD being uninitialized variable in templated class instantiated for int128.
Probably due to overall lack of int128 support.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It's a part of big project. I tried just now to cut out the part in question and did not succeed: it's either too big to be easily understanded (and it's commercial project, so I simply can't put it all here) or cppcheck finds no error.
The offending item is some custom hashtable that is developed specifically to work with large integers (64/128 bit) and as so is templated by used type. It's marked in header for intantiation as
extern template class HashTableInteger<int64_t>;
extern template class HashTableInteger<uint64_t>;
extern template class HashTableInteger<int128_t>;
extern template class HashTableInteger<uint128_t>;
and later in code after class definition as
template class HashTableInteger<int64_t>;
template class HashTableInteger<uint64_t>;
template class HashTableInteger<int128_t>;
template class HashTableInteger<uint128_t>;
the usual thing with splitting templated class declaration/definition to avoid excess compilation and keep header short and neat.
The method in question is protected method that gets templated type value as one of the arguments.
I do believe the main reason behind ths FP is general lack of support for int128 in cppcheck - I posted here some time ago it's complains about shifting 128-bit value by more than 32 bits being an error. The fact that cppcheck doesn't complains about any other instantation of same hashtable support this assumption quite well in my eyes (just tried 8/16/32-bit versions too, just to be sure).
I'll try to make smallest possible example, however, I keep my hopes low at the moment... :-(
Last edit: Dmitry Kuteynikov 2021-08-28
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
that is usually the case. there is some more detail somewhere that is confusing cppcheck somehow. very hard to guess.
I suggest that you take your commercial code. then step by step remove various blocks of code. includes, classes, functions, .. as long as you can still reproduce the FP continue.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok. I did it. It compiles and cppcheck says bad words. Took quite a few attempts.
There are two pair of files besides CMakeLists.txt.
HashTable - support stuff that doesn't really matters, most everything cut out anyway.
HashTableInteger - the templated class in question, whose methods are FP-ed as uninitialized variables.
What is the value of the __extension__ macro? It seems that cppcheck does not know about it.
Just a tip: when reducing code, it does not matter if it still compiles, as long as cppcheck accepts it and still reproduces the error.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It's recommended way to mark custom gcc types like __int128 so gcc -Wpedantic won't complain that they're not ISO.
My attempts on reducing example in mostly same way resulted in no complains from cppcheck... That's my luck... ;-)
Last edit: Dmitry Kuteynikov 2021-08-28
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Maybe __extension__ should be part of some .cfg configuration/platform then? At least passing -D__extension__ to cppcheck fixes the error message for me.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@CHR, @Daniel Marjamäki - many thanks!
Both your solutions works (the define and the library specification). This doesn't resolve some other issues with int128, namely bit shifts, but "this is another story".
Thanks a lot!
👍
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
CppCheck complains about METHOD being uninitialized variable in templated class instantiated for int128.
Probably due to overall lack of int128 support.
Thanks for reporting.. could you create a minimal example that reproduce the FP?
It's a part of big project. I tried just now to cut out the part in question and did not succeed: it's either too big to be easily understanded (and it's commercial project, so I simply can't put it all here) or cppcheck finds no error.
The offending item is some custom hashtable that is developed specifically to work with large integers (64/128 bit) and as so is templated by used type. It's marked in header for intantiation as
and later in code after class definition as
the usual thing with splitting templated class declaration/definition to avoid excess compilation and keep header short and neat.
The method in question is protected method that gets templated type value as one of the arguments.
I do believe the main reason behind ths FP is general lack of support for int128 in cppcheck - I posted here some time ago it's complains about shifting 128-bit value by more than 32 bits being an error. The fact that cppcheck doesn't complains about any other instantation of same hashtable support this assumption quite well in my eyes (just tried 8/16/32-bit versions too, just to be sure).
I'll try to make smallest possible example, however, I keep my hopes low at the moment... :-(
Last edit: Dmitry Kuteynikov 2021-08-28
that is usually the case. there is some more detail somewhere that is confusing cppcheck somehow. very hard to guess.
I suggest that you take your commercial code. then step by step remove various blocks of code. includes, classes, functions, .. as long as you can still reproduce the FP continue.
That's exactly what I'm doing at the moment. The problem is, I don't have much free time for this. I'll definitely try my best, though.
Ok. I did it. It compiles and cppcheck says bad words. Took quite a few attempts.
There are two pair of files besides CMakeLists.txt.
HashTable - support stuff that doesn't really matters, most everything cut out anyway.
HashTableInteger - the templated class in question, whose methods are FP-ed as uninitialized variables.
Just in case: Cppcheck 1.90
Last edit: Dmitry Kuteynikov 2021-08-28
Further reduced example:
What is the value of the
__extension__
macro? It seems that cppcheck does not know about it.Just a tip: when reducing code, it does not matter if it still compiles, as long as cppcheck accepts it and still reproduces the error.
It's recommended way to mark custom gcc types like
__int128
sogcc -Wpedantic
won't complain that they're not ISO.My attempts on reducing example in mostly same way resulted in no complains from cppcheck... That's my luck... ;-)
Last edit: Dmitry Kuteynikov 2021-08-28
Maybe
__extension__
should be part of some .cfg configuration/platform then? At least passing-D__extension__
to cppcheck fixes the error message for me.Try to add
--library=gnu
to your command line then__extension__
should be handled.@CHR, @Daniel Marjamäki - many thanks!
Both your solutions works (the define and the library specification). This doesn't resolve some other issues with int128, namely bit shifts, but "this is another story".
Thanks a lot!