COP-init-order (C++ only)
In this section:
Synopsis
Data members are initialized with other data members that are in the same initialization list.
Enabled by default
No
Severity/Certainty
Medium/Medium

Full description
Data members are initialized with other data members that are in the same initialization list. This can cause confusion, and might produce incorrect output, because data members are initialized in order of their declaration and not in the order of the initialization list.
Coding standards
- CERT OOP37-CPP
Constructor initializers should be ordered correctly
- CWE 456
Missing Initialization
Code examples
The following code example fails the check and will give a warning:
class C{
int x;
int y;
C():
x(5),
y(x) //Initializing using another member
{}
};
The following code example passes the check and will not give a warning about this issue:
class C{
int x;
int y;
C():
x(5),
y(5) //OK
{}
};