The std::enable_shared_from_this
class is a (template) mixin, recommended for use to enable creating shared pointers from a given object (or its address), which all have common ownership of the object.
The thing is, that if you have an class T which:
- Has virtual methods
- inherits from
std::enable_shared_from_this<T>
(and the inheritance must be public as detailed at the link above; otherwise the mixin is useless) - Gets compiled with GCC with
-Wnon-virtual-dtor
(perhaps also with clang, I'm not sure)
you get warnings about the non-virtual destructor of std::enable_shared_from_this
.
My question is - where is the fault here? That is...
- Should
std::enable_shared_from_this
have a virtual destructor? (I don't think so) - Should the non-virtual-destructor warning employ some criterion for when it is emitted (if at all enabled, that is)?
- Should the destructor of
std::enable_shared_from_this
be made protected? (And will this even work?) - Should classes with this mixin not have virtual methods at all?
I'm confused.