Generally speaking, it appears hard to avoid undefined behavior when data members of classes aren’t consistently being initialized. We saw a few cases recently:
- Fix MSVC warning C26495: `ZwQuerySystemInformation`, `m_MetaDataObjectValue` uninitialized by N-Dekker · Pull Request #3843 · InsightSoftwareConsortium/ITK · GitHub
- BUG: Fix uninitialized value `ImageRegistrationMethodv4::m_NumberOfLevels` by jhlegarreta · Pull Request #3845 · InsightSoftwareConsortium/ITK · GitHub
- COMP: Fix MSVC warning C26495: `m_PositionIndex` uninitialized by N-Dekker · Pull Request #3849 · InsightSoftwareConsortium/ITK · GitHub
Hereby I’m proposing to consistently use in-class default member initializers for data members of ITK classes “by default”, and only leave data members uninitialized in very specific cases (specific cases, typically where the run-time performance cost of initialization would be too high).
For those data members that did not yet have an in-class default member initializer, the following PR proposes to add a {}
initializer:
The PR is limited to classes whose instances are created by New()
, assuming that for those classes, the cost of the added {}
initialization is neglectable compared to the cost of object creation. Please have a look: STYLE: Add in-class `{}` member initializers to objects created by New() by N-Dekker · Pull Request #3851 · InsightSoftwareConsortium/ITK · GitHub