diff --git a/include/cereal/types/optional.hpp b/include/cereal/types/optional.hpp index 3b244465..a68c055b 100644 --- a/include/cereal/types/optional.hpp +++ b/include/cereal/types/optional.hpp @@ -56,9 +56,8 @@ namespace cereal { if (nullopt) { optional = std::nullopt; } else { - T value; - ar(CEREAL_NVP_("data", value)); - optional = std::move(value); + optional.emplace(); + ar(CEREAL_NVP_("data", *optional)); } } } // namespace cereal