Menu

FP: missing override with multiple inheritance and nested class

2023-03-14
2023-03-15
  • Lionel Gimbert

    Lionel Gimbert - 2023-03-14

    Hello,

    In a bit of code involving multiple inheritance and nested classes I have an issue where cppcheck don't attribute the proper inheritance and think two independant classes are based/derived from each other.

    The issue can be seens with the following code with 2.10 and current head of main.

    class A
    {
      public:
        class Nested
        {
          public:
          virtual ~Nested() = default;
        };
    };
    
    class B
    {
      public:
        class Nested
        {
          public:
          virtual ~Nested() = default;
        };
    };
    
    class C : public A, public B
    {
      public:
        class Nested : public A::Nested, public B::Nested
        {
        };
    };
    

    Which produce the following output:

    test.cpp:7:16: style: The destructor '~Nested' overrides a destructor in a base class but is not marked with a 'override' specifier. [missingOverride]
    virtual ~Nested() = default;
    ^
    test.cpp:17:16: note: Virtual destructor in base class
    virtual ~Nested() = default;
    ^
    test.cpp:7:16: note: Destructor in derived class
    virtual ~Nested() = default;

    Looking at cppcheck debug output, it consider that A::Nested is derived from B::Nested

    (and, yes, the inheritance scheme here is debatable)

     

    Last edit: Lionel Gimbert 2023-03-14
  • CHR

    CHR - 2023-03-14

    Thanks for reporting, fixed by https://github.com/danmar/cppcheck/pull/4894

     
  • Lionel Gimbert

    Lionel Gimbert - 2023-03-15

    Damn, that was quick!
    Thanks.

     

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.