6.8.5 Initializers and POD - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18) +--- Forum: MISRA C++:2008 rules (https://forum.misra.org.uk/forumdisplay.php?fid=19) +---- Forum: 6.8 Declarators (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=137) +---- Thread: 6.8.5 Initializers and POD (/showthread.php?tid=978) |
6.8.5 Initializers and POD - martin.dowie - 04-09-2013 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 Re: 6.8.5 Initializers and POD - misra cpp - 11-10-2016 The rule does not require that all classes have constructors, but if a constructor is provided, it must initialise all non-static members |