Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Misra C++ 2023 14.1.1: clarify inherited members
#1
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 {
  int bm;
};

class Derived final : private Base {
private:
  int dm;
};

"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 {
private:
  int dm;
};

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
Reply
#2
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'
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)