Friend declarations shall not be used
Friend declarations shall not be used.
You declare a function as friend of a class to access private members of the class outside the class scope.
class A
{
int data;
public:
// operator+ can access private members of class A such as data
friend A const operator+(A const& lhs, A const& rhs);
};Code with friend functions can be difficult to maintain. For instance, if class
myClass has a friend class anotherClass, when you
change a data member of myClass, you have to find all instances of its
usage in member functions of anotherClass.
The rule checker flags all uses of the friend keyword.
The checker follows specifications of AUTOSAR C++ 14 release 18-03 (March 2018).
However, release 18-10 and later releases of AUTOSAR C++14 allows an exception for
comparison operators such as operator==. If the rule checker flags the
use of comparison operators, add a comment justifying the result. See Address Polyspace Results Through Bug Fixes or Justifications.
If you expect a rule violation but do not see it, refer to Coding Standard Violations Not Displayed.
| Group: Member Access Control |
| Category: Required, Automated |