AUTOSAR C++14 Rule A3-1-5
A function definition shall only be placed in a class definition if (1) the function is intended to be inlined (2) it is a member function template (3) it is a member function of a class template
Since R2020b
Description
Rule Definition
A function definition shall only be placed in a class definition if (1) the function is intended to be inlined (2) it is a member function template (3) it is a member function of a class template.
Rationale
Placing a function definition in a class definition is allowed only if:
The function is intended to be inlined. Placing the definition of a member function in the class definition instructs the compiler to inline the member function. Inlining small functions avoids the run-time overhead of function calls and improves the performance of the compiled executable. But if you place the definition of a large member function inside the class definition unaware of this implicit inlining, the compiled executable might be too large.
The function is a member function template or a member of a class template. These coding practices reduce repetitions of template syntax elements (for example, the parameter list). This reduction improves the readability and maintainability of the code.
Polyspace Implementation
The checker uses the heuristic that, unless you explicitly use the
inline
keyword, you intend to inline only small functions that consist
of no more than one statement. The checker interprets AUTOSAR C++14 Rule A3-1-5 in the
following way.
For nontemplate member functions and member functions of nontemplate classes, the checker flags one-line member functions defined outside a class and larger member functions defined inside a class.
For template member functions and member functions of template classes, the checker flags any member function that is defined outside a class.
Polyspace® does not report a violation of this rule for constexpr
and
consteval
functions.
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: Basic concepts |
Category: Required, Partially automated |