Skip to content

Inheritance from Print class with no virtual destructor #625

@smartynov

Description

@smartynov

I'm trying to create a library that uses PubSubClient. I create a mqttClient = new PubSubClient on initialization and I want to delete mqttClient in some cases. However, my compiler (platformio) issues a warning "deleting object of polymorphic class type 'PubSubClient' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]".

As far as I understood the cause for this warning is that PubSubClient class is inherited from Print class, and there is no virtual destructor in Print class. This is discussed in arduino/Arduino#4466 – this PR exists from 2016, however it is still not merged.

While most accurate solution will be adding virtual destructor to Print base class, I can't see any advantages for PubSubClient to be derived from Print class. I suggest to remove this inheritance and get rid of undefined behaviour.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions