diff --git a/Utilities/std/cm/optional b/Utilities/std/cm/optional index 1577fa074f..6a03a6c062 100644 --- a/Utilities/std/cm/optional +++ b/Utilities/std/cm/optional @@ -12,6 +12,9 @@ #if defined(CMake_HAVE_CXX_OPTIONAL) # include // IWYU pragma: export #else +# if defined(__GNUC__) && !defined(__clang__) +# include +# endif # include # include @@ -121,7 +124,13 @@ private: T value; // Explicit constructor and destructor is required to make this work - _mem_union() noexcept {} + _mem_union() noexcept + { +# if defined(__GNUC__) && !defined(__clang__) + // Some versions of GCC complain about uninitialized memory + std::memset(this, 0, sizeof(*this)); +# endif + } ~_mem_union() noexcept {} } _mem; };