Menu

pointer of array member variable is not initialized in the constructor

AlexHsieh
2017-08-16
2017-08-21
  • AlexHsieh

    AlexHsieh - 2017-08-16

    Hi,
    I use cppcheck-1.80 to check the following code

    char list[2][3] = {
    {1,2,3},
    {1,2,3}
    };

    class A{
    public:
    char (*pList)[3];
    A(){pList = list;};
    ~A(){};
    };

    class B{
    public:
    char (*pList)[3];
    B();
    ~B(){};
    };
    B::B(){pList = list;}

    , and get

    Summary: Member variable 'B::pList' is not initialized in the constructor.
    Message: Member variable 'B::pList' is not initialized in the constructor.

    but I think 'B::pList' is initialized (as A::pList).
    Is this a bug of cppcheck-1.80?
    or
    'B::pList' is not initialized indeed?

     
  • Daniel Marjamäki

    Thanks! It is a false positive. I created http://trac.cppcheck.net/ticket/8170

     

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.