Cppcheck v2.6 has reported many of the uninitMemberVar warnings and they look like false positives:
SeverityCppchecker Message
(warning) [uninitMemberVar] Member variable 'TestAverage::m_average' is not initialized in the constructor. [cppCheck]
(warning) [uninitMemberVar] Member variable 'TestAverage::m_rangeMin' is not initialized in the constructor. [cppCheck]
In the code snippet below, the referenced class data members TestAverage::m_average and TestAverage::m_rangeMin are initialized in ctor.
They are not initialized at declaration because they are initialized w/ values passed to ctor as param, values are not know at declaration, they cannot be init at declaration, neither it’s required for a valid, well formed C++ code. I believe those are false positives issues with cppcheck but if you see a problem please explain it, maybe we are missing something.
-
class TestAverage
{
float m_average;
int m_rangeMin;
int m_rangeMax {0};
TestAverage *m_ra {nullptr};
int m_allowance {0};
public:
TestAverage(int average, int min, int max)
: m_average(average)
, m_rangeMin(min)
, m_rangeMax(max)
{
float a {static_cast<float> (average) / m_arrSize};
for (auto &v : m_value) v = a;
}</float>
Greetings CHR.
These false positives are still repro with this latest release version 2.9 as well. https://github.com/danmar/cppcheck/releases/tag/2.9
Could you please prioritize fixes for these uninitMemberVar false-positives.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The sample that you posted does not reproduce the issue. Unless there is a minimal reproducer, the issue cannot be addressed.
Also, please use the proper tags ~~~ around your code.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Greetings Cppcheck team!
Cppcheck v2.6 has reported many of the uninitMemberVar warnings and they look like false positives:
Severity Cppchecker Message
(warning) [uninitMemberVar] Member variable 'TestAverage::m_average' is not initialized in the constructor. [cppCheck]
(warning) [uninitMemberVar] Member variable 'TestAverage::m_rangeMin' is not initialized in the constructor. [cppCheck]
In the code snippet below, the referenced class data members TestAverage::m_average and TestAverage::m_rangeMin are initialized in ctor.
They are not initialized at declaration because they are initialized w/ values passed to ctor as param, values are not know at declaration, they cannot be init at declaration, neither it’s required for a valid, well formed C++ code.
I believe those are false positives issues with cppcheck but if you see a problem please explain it, maybe we are missing something.
-
class TestAverage
{
float m_average;
int m_rangeMin;
int m_rangeMax {0};
public:
TestAverage(int average, int min, int max)
: m_average(average)
, m_rangeMin(min)
, m_rangeMax(max)
{
float a {static_cast<float> (average) / m_arrSize};
for (auto &v : m_value) v = a;
}</float>
};
v2.9 has just been released. It seems that the false positves have been fixed.
Thanks CHR.
Could you point the release notes of v2.9 that mentions these uninitMemberVar false-positives been fixed?
Minor bugfixes ususally aren't mentioned in the release notes. The fix could also be in 2.7 or 2.8.
Greetings CHR.
These false positives are still repro with this latest release version 2.9 as well.
https://github.com/danmar/cppcheck/releases/tag/2.9
Could you please prioritize fixes for these uninitMemberVar false-positives.
The sample that you posted does not reproduce the issue. Unless there is a minimal reproducer, the issue cannot be addressed.
Also, please use the proper tags
~~~
around your code.