A12-4-1 - Does it apply to private inheritance? - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18) +--- Forum: AUTOSAR C++:2014 rules (https://forum.misra.org.uk/forumdisplay.php?fid=185) +--- Thread: A12-4-1 - Does it apply to private inheritance? (/showthread.php?tid=1607) |
A12-4-1 - Does it apply to private inheritance? - cgpzs - 15-03-2022 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? 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! RE: A12-4-1 - Does it apply to private inheritance? - kent.dorfman766 - 18-03-2022 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. RE: A12-4-1 - Does it apply to private inheritance? - misra cpp - 22-03-2022 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. RE: A12-4-1 - Does it apply to private inheritance? - cgpzs - 22-03-2022 Thanks for the clarification and heads-up! RE: A12-4-1 - Does it apply to private inheritance? - misra cpp - 29-04-2022 This thread is now closed Please post any related questions as a new thread |