Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A12-4-1 - Does it apply to private inheritance?
#1
Hi,

Rule A12-4-1 says:
"Destructor of a base class shall be public virtual, public override or protected non-virtual."

Does it apply in the context of private inheritance? In that case, it's not possible to obtain a pointer to the Base class, therefore mitigating the risks the rule is trying to prevent from.


Code:
class Base  // A12-4-1 violated here?
{};

class Derived final : private Base
{};

The goal here is to be able to create both Base and Derived objects; therefore Base cannot have a protected non-virtual destructor. A public virtual destructor would come with performance penalties.

Thanks!
Reply
#2
without overtly saying it, what I got from reading the rules is that they seem to want to discourage heirarchies where the base is not a purely abstract interface. ie. all virtuals.
Reply
#3
Currently this rule applies in the context of private inheritance, so both classes in your example would be flagged as violations, as they don't declare destructors.

For the next version of MISRA C++, we are proposing to clarifying that this rule only applies in the context of public inheritance. We aren't currently planning to say anything about private or protected inheritance.
Posted by and on behalf of
the MISRA C++ Working Group
Reply
#4
Thanks for the clarification and heads-up!
Reply
#5
This thread is now closed

Please post any related questions as a new thread
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)