Menu

uninitMemberVar : false positive on member variable when type is std::map

2020-11-25
2021-01-28
  • ttressieres

    ttressieres - 2020-11-25

    In the following code, I receive this error

    bug_cache.cpp:11:14: warning: Member variable 'CacheDF::values_' is not initialized in the constructor. [uninitMemberVar]

    explicit CacheDF(double * df) : df_(df) {}
    
    #include <map>
    #include <set>
    
    //-----------------------------------------------------------------------------
    
    class CacheDF
    {
    public:
        //using Values = std::set<double>;
        using Values = std::map<int,double>;
        explicit CacheDF(double * df) : df_(df) {}
    private:
        double * df_{nullptr};
        Values * values_{nullptr};
    }; 
    

    But if I replace std::map with std::set, the error goes away.

    Regards,

     

    Last edit: Daniel Marjamäki 2021-01-28
  • CHR

    CHR - 2021-01-27

    Is this still in moderation?

     
  • CHR

    CHR - 2021-01-27

    This reproduces with v2.3. I have created a ticket here: https://trac.cppcheck.net/ticket/10142

     
  • Daniel Marjamäki

    This reproduces with v2.3.

    I hope you test with latest main also.

     
  • CHR

    CHR - 2021-01-28

    Yes, it still reproduces.

     
    👍
    1

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.