Menu

[Cppcheck v2.6] False positive uninitMemberVar warnings

2022-09-01
2022-09-05
  • Siva Ramaraju

    Siva Ramaraju - 2022-09-01

    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};

     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>

     TestAverage(int average, int min, int allowance, TestAverage &ra)
     :   m_average(average)
     ,   m_rangeMin(min)
     ,   m_ra(&ra)
     ,   m_allowance(allowance)
     {
         float a {static_cast<float> (average) / m_arrSize};
         for (auto &v : m_value) v = a;
     }
     ..
     ..
    

    };

     
  • CHR

    CHR - 2022-09-01

    v2.9 has just been released. It seems that the false positves have been fixed.

     
  • Siva Ramaraju

    Siva Ramaraju - 2022-09-01

    Thanks CHR.
    Could you point the release notes of v2.9 that mentions these uninitMemberVar false-positives been fixed?

     
  • CHR

    CHR - 2022-09-01

    Minor bugfixes ususally aren't mentioned in the release notes. The fix could also be in 2.7 or 2.8.

     
  • Siva Ramaraju

    Siva Ramaraju - 2022-09-05

    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.

     
  • CHR

    CHR - 2022-09-05

    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.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.