Menu

False warning with Delegating constructor

wibek
2015-05-27
2015-05-27
  • wibek

    wibek - 2015-05-27

    When I put a delegating constructor outside the class definition cppcheck gives a warning "Member variable is not initialized in the constructor":

    class Bar
    {
    public:
      Bar();
      explicit Bar(int i);
      Bar(const Bar &other) = delete;
      ~Bar() {}
    
    private:
      string *strs;
    };
    
    Bar::Bar() : Bar(100) {}       // <<---- warning: "Member variable is not initialized"
    Bar::Bar(int i, bool b) : strs(nullptr) {}
    

    When I put the delegating constructor inside the class definition everything is fine:

    class Bar
    {
    public:
      Bar(): Bar(100) {}         // <<----- no warning
      explicit Bar(int i);
      Bar(const Bar &other) = delete;
      ~Bar() {}
    
    private:
      string *strs;
    };
    
    Bar::Bar(int i, bool b) : strs(nullptr) {}
    

    Using version 1.69.

     

    Last edit: wibek 2015-05-27
  • Alexander Mai

    Alexander Mai - 2015-05-27

    Sounds like a bug (false positive). I suggest you file a bug report on http://trac.cppcheck.net/ then.

    There seems to be a related ticket already: http://trac.cppcheck.net/ticket/6580

     

    Last edit: Alexander Mai 2015-05-27

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.