AUTOSAR C++14 Rule A11-0-1
Description
Rule Definition
A non-POD type should be defined as class.
Rationale
A POD (Plain Old Data) type can be exchanged with C code in its binary form, and can be
safely copied by using the std::memcpy
function. Scalar types, C-style
structures and unions, and arrays of these types are all examples of POD types. However, the
C++ language also allows you to create structures and unions that are non-POD types. Such
structures and unions can provide custom-defined constructors, have nonstatic data members
with private or protected access control, have an interface, and implement an
invariant.
A software developer typically expects object-oriented concepts such as encapsulation to be implemented by using classes. In addition, a class specifier forces the type to provide private access control for all its members by default and is naturally suited for implementing encapsulated types. So, to create easily readable and maintainable code, define a non-POD type as a class instead of a structure or a union.
Polyspace Implementation
The checker flags a structure or a union in your code is not a POD type. This includes structures and unions that are instantiated by using templates.
For a simplified explanation of a POD type in C++ language, see the previous section. For a full specification of a POD type, see the C++ reference manual.
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: Member access control |
Category: Advisory, Automated |
Version History
Introduced in R2020b