MISRA Discussion Forums

Full Version: 6.8.5 Initializers and POD
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Rule 8-5-1 (Required) "All variables shall have a defined value before they are used."

My reading of this rule leads me to the conclusion that "POD" classes are effectively not allowed, since any user-defined constructor provided to give initial values to non-static member data results in the class no longer being POD. Example:

[code]// Standard headers
#include
#include // std::is_pod

// User-defined structs...how many are POD?
struct Trivial_Ctor { int i; };
struct With_User_Defined_Ctor { int i; With_User_Defined_Ctor() { } };
struct With_Initialised_Member { int i; With_Initialised_Member() : i(0) { } };

int main()
{
std::cout
The rule does not require that all classes have constructors, but if a constructor is provided, it must initialise all non-static members