Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A12-1-1 - Does it apply to POD structs?

Does A12-1-1 apply to POD structs? Example:

struct Foo
  int x;
  int y;

The members of `Foo` are by default uninitialized. Does A12-1-1 require `Foo` to explicitly initialize its members, like this?

struct Foo
  int x{};
  int y{};

Please note that the above change has some implications, namely that `Foo` is no longer trivial. As such, compilers will warn about performing `memcpy` operations on them. This is a problem for serializer/deserializer type of code.

found this in the parasoft docs...reposting without permission. Dodgy 

All member variables should be initialized in constructor [AUTOSAR-A12_1_1-b]


Constructors of 'class' and 'struct' should initialize all member variables.

The rule checks if a member variable is initialized:
- in constructor initialization list
- inside body of constructor
- inside body of function called from constructor (three levels of nested
  function's calls are checked)
- directly in class (C++11).

If there is no constructor at all a violation is reported for 'class' only.
You can enable INIT-15 to get a violation for 'struct' too.

See also: INIT-10, INIT-14, INIT-15, MISRA-030


The rule assumes that member variable might be initialized
by passing its non-const pointer to an external function.

Member variables which are static or have class or struct type are ignored.
Static variables should not be initialized in constructor.
Class/struct variables are assumed to be initialized by their own constructors.

If in constructor is called default copy assignment operator,
then the rule assumes that all member variables are initialized.

If in constructor is called a member function from the current class with
non-accessible body, then this rule assumes that all member variables are


Prevents reading from uninitialized variables.

Thanks for the snippet! I experience the same with static analyzers, they split into multiple diagnostics to allow for a finer level of control and specific project deviations.
The intended reading of the rule is ‘if a class has a user-declared constructor, then ….’.  As a POD struct cannot have a user-declared constructor (that would stop it being POD), the rule doesn’t apply.
Posted by and on behalf of
the MISRA C++ Working Group
Thank you for the clarification!
Thread closed
Posted by and on behalf of
the MISRA C++ Working Group

Forum Jump:

Users browsing this thread: 1 Guest(s)