Skip to main content

IAR Embedded Workbench for RX 5.20

COP-init-uninit (C++ only)

In this section:
Synopsis

An initializer list reads the values of still uninitialized members.

Enabled by default

Yes

Severity/Certainty

High/High

highhigh.png
Full description

The expressions used to initialize a class member contain other class members, that have not yet been initialized themselves. The order in which they are initialized depends on the order of their declarations in the class definition and not on the order in which the members appear in the list, which might feel counter-intuitive. This might cause some of the object's attributes to have incorrect values, leading to logic errors or an application crash if the class handles dynamic memory.

Coding standards
CWE 456

Missing Initialization

Code examples

The following code example fails the check and will give a warning:

class C{
  int y;
  int x;
  C():
    x(5),
    y(x)  //x has not been initialized yet,
          //as y was defined first (line 2)
  {}
};

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(x)  //OK - x has been initialized
  {}
};