AUTOSAR C++14 Rule A9-3-1
Member functions shall not return non-constant "raw" pointers or references to private or protected data owned by the class
Description
Rule Definition
Member functions shall not return non-constant "raw" pointers or references to private or protected data owned by the class.
Rationale
Returning a nonconstant pointer or reference to private or protected class-owned data enables clients to externally access and modify the state of the object without an interface. Such access without an explicit interface might bypass the private/protected data access hierarchy of the class, which might result in unexpected behavior and lead to bugs.
This rule applies to data that is owned by the class. Nonconstant handles to objects that are shared between different classes might be returned. Classes that mimic smart pointers and containers do not violate this rule.
Polyspace Implementation
The checker flags a rule violation only if a member function returns a
non-const
pointer or reference to a nonstatic data member.
The rule does not apply to static data members.
Troubleshooting
If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Classes |
Category: Required, Partially automated |
Version History
Introduced in R2019a