Missing deprecation of virtual methods when changing functions contsness
Recently, in PDELab
, we have noticed several (not nice) bugs due that some virtual methods have changed to be const
without a proper deprecation (See 0cfd4a01). When adding or removing const
-ness of a function, you are actually changing the signature of the function and hence, changing the behavior of all of those inheriting and overriding it.
I understand that is an error of the two sides. One for not using a deprecation method after the change, and second because the downstream project was not using the override
keyword. But is a simple change here that may save a lot of troubles for all of those that forgot the override
keyword.
struct Class {
// new interface
virtual void my_function() const // <- const was added
{
// similar functionality as non const function before ...
}
// old interface
DUNE_DEPRECATED virtual void my_function()
{
// forward to the new method
const_cast<const Class*>(this)->my_function();
}
};
Edited by Santiago Ospina De Los Ríos