Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eclipse cdt's code analysis doesn't understand virtual inheritance

I have a class hierarchy with two diamonds caused by having to extend all the classes in a decorator pattern (they already extend virtually):

namespace _sandbox {

class A {
    public:
        virtual ~A() {}
        virtual void foo()=0;
};

class ADecorator : public virtual A {
    private:
        A* decoratedA;
    public:
        ADecorator(A* a) : decoratedA(a) {}
        void foo() {return decoratedA->foo();}
};

class AImpl : public virtual A {
    public:
        void foo() {};
};

class B : public virtual A {
    public:
        virtual ~B() {}
        virtual void bar()=0;
};

class BDecorator : public ADecorator, public B {
    private:
        B* decoratedB; //Copy of the pointer with a different type
    public:
        BDecorator(B* b) : ADecorator(b), decoratedB(b) {}
        void bar() {return decoratedB->bar();}
};

class BImpl : public B, public AImpl {
    public:
        void bar() {};
};

B* b = new BDecorator(new BImpl());

}

Graphically:

       A
      /|\
   v /v| \ v
    /  |  \
AImpl  B  ADecorator
   |  / \  |
   | /   \ |
   |/     \|
BImpl     BDecorator

GCC compiles this with no problem, but eclipse's code analysis insists that BDecorator doesn't implement foo()

The type '_sandbox::BDecorator' must implement the inherited pure virtual method '_sandbox::A::foo'

I can silence this problem by setting this type of error to "Info" on the settings, but I'm wondering is there's actually an error in the code that GCC overlooked, or if there's something I can do to make the Code Analysis accept the code? If it's possible, I'd rather not have this code analysis feature silenced, so I can easily detect actual mistakes.

How is BImpl different than BDecorator in terms of what methods it implements? The code analysis doesn't complain anything about BImpl, yet the way they have an implementation of foo() is similar.

like image 943
Baro Avatar asked Mar 13 '14 12:03

Baro


1 Answers

I think you might have to index your code again. Right click on your project in the project explorer, click on Index and then click on Freshen All files. This will force eclipse to index all your code.

like image 51
Hrushikesh Kulkarni Avatar answered Oct 31 '22 07:10

Hrushikesh Kulkarni