![]() |
|
Misra C++ 2023 14.1.1: clarify inherited members - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18) +--- Forum: MISRA C++:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=188) +---- Forum: 4.14 Member access control (https://forum.misra.org.uk/forumdisplay.php?fid=200) +---- Thread: Misra C++ 2023 14.1.1: clarify inherited members (/showthread.php?tid=1757) |
Misra C++ 2023 14.1.1: clarify inherited members - sks - 03-11-2025 Hi everybody, how should rule 14.1.1 handle inherited members, especially given the extra comment regarding "privileged access to data members". For instance, consider Code: struct Base {"Base" only has a single public member, thus is compliant. "Derived" has a private member "dm" directly and another private member "bm" by inheritance. This is compliant I think. However, what about public inheritance: Code: class Derived final2 : public Base {My assumption is that this now has a public and a private member and is thus non-compliant. Can you please clarify: - Are inherited members treated like non-inherited ones, taking into account the kind of inheritance? - Does the additional note regarding derived classes requiring privileged acccess only refer to the discouraged usage of "protected" or should it enforce private members in class "Base" in case some derived class uses the member (ie. to avoid having to rely on private inheritance)? Thanks for your help, regards Sebastian RE: Misra C++ 2023 14.1.1: clarify inherited members - misra cpp - 14-11-2025 We agree with your interpretation: final is compliant and final2 is non-compliant. There may be an issue with the wording of the rule. In final, it can be argued that bm is not a private member (of final), but is inaccessible. We will look to see whether we should change the requirement to 'all members should be public or private/inaccessible' |