Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] Over-eager "virtual method but no virtual dtor" warning

This is driving me mad,

Like everyone here I like warning-less code, I compile with -pedantic -Wall -Wextra as any sane person should but there's this warning that I cannot get to go away.

I cannot think of any instance where the warning is justified either.

Let me distill the use-case I have encountered this warning in and why it isn't useful.

class OnEventListener {
protected:
    OnEventListener() { }
    ~OnEventListener() { /*deregister with all emitters* }
    virtual void notifyOfEvent() =0;
void onEvent() { notifyOfEvent(); } //not sure why I do this now I am writing it, I have this habit of wrapping virtuals, either way no harm
};

Then something like:

class Whatever: protected OnEventListener {
/*whatever*/
};

The class "whatever" gets the warning. There is no way that I can be dealing with a Whatever as a OnEventListener, because the inheritance is private. Furthermore the destructor itself is protected so even if I did get hold of a Whatever by the OnEventListener I couldn't destroy it this way anyway.

So this leads me to state:

Even if it were "class Whatever: public OnEventListener {" the warning would be wrong.

Lets distill this even further.

class A {
protected:
    A() { }
    ~A() { }
    virtual void f() =0;
};

class B: protected A {

    void f() { }
};

How could this go wrong? What is the warning warning me of?

I suppose I could friend A (which I have actually....) from something that deals with Bs as As .... but this is at a stretch because I'd have to write some really obscure code to get this, to create Bs but never manage them....

Anyway, bug or am I missing something?

Alec


Back to the top