I want to deprecate some functions in an old codebase. My header files look like:
foo.h:
class A
{
[[deprecated]] virtual int F0()=0;
}
bar.h:
class B: A
{
[[deprecated]] int F0();
}
When I compile this in VS2017, I get a deprecated warning in class B because the name was previously deprecated in class A. If I remove the deprecated directive in B, I also get the warning for the same reason. That seems kind of unfair.
What is the right way around this?
If a base class method is marked as deprecated, it doesn't matter if an overriding method in a derived class is also marked as deprecated or not. The method is still deprecated in the derived class.
Just like an overriding method doesn't need to use
virtualexplicitly, but the method is still virtual. The same is true with[[deprecated]], too.cppreference.com says this:
https://en.cppreference.com/w/cpp/language/attributes/deprecated