AutosarC++17_10-A11.3.1¶
Friend declarations shall not be used
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
Friend declarations reduce encapsulation and result in code that is more difficult to maintain.
Example
// $Id: A11-3-1.cpp 271696 2017-03-23 09:23:09Z piotr.tanski $
class A {
public:
A &operator+=(A const &oth);
friend A const operator+(A const &lhs, A const &rhs); // Non-compliant
};
class B {
public:
B &operator+=(B const &oth);
};
B const operator+(B const &lhs, B const &rhs) // Compliant
{
// Implementation
}
See Also
- JSF December 2005 [7]: AV Rule 70 A class will have friends only when a function or object requires access to the private elements of the class, but is unable to be a member of the class for logical or efficiency reasons.
- HIC++ v4.0 [8]: 11.2.1 Do not use friend declarations.
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
friend_class |
Do not use friend type declarations. |
None |
False |
friend_decl |
Do not use friend declarations. |
None |
False |
Options¶
This rule shares the following common options: confidence, exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
allow_comparison_operators¶
allow_comparison_operators : bool = False