AUTOSAR C++14 Rule A12-6-1
All class data members that are initialized by the constructor shall be initialized using member initializers
Description
Rule Definition
All class data members that are initialized by the constructor shall be initialized using member initializers.
Rationale
It is inefficient to initialize data members of a class by assigning a copy of passed values to them in the body of a constructor. For instance, this code is inefficient:
class foo{ private: int i; public: foo(int input){ i = input; //... } };
Initialize data members by using an initializer list.
Initialize data members by using default member initializers.
To increase the efficiency of your code and to protect your code from using an uninitialized data member, use the preceding methods to initialize data members of a class.
Polyspace Implementation
Polyspace® flags the constructor definition of a class if the constructor initializes the nonstatic data members of the class in its body by copying the passed values to the data members. Polyspace does not flag constructors with uninitialized 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: Special Member Functions |
Category: Required, Automated |
Version History
Introduced in R2019a