From c1ead85dff393f6e5c356073375bc955e1714403 Mon Sep 17 00:00:00 2001 From: Philip Pronin Date: Mon, 24 Oct 2016 23:27:16 -0700 Subject: [PATCH] fix Expected<..., eUnion> move / copy ctor Summary: Consider `Expected<..., eUnion>(Expected&&)` ctor, where `ExpectedUnion` move ctor would be called first, which is noop leaving `which_` uninitialized; then `MoveConstructible` ctor is executed, calling `assignValue()`, which performs action depending on uninitialized `which_`. Reviewed By: yfeldblum Differential Revision: D4073199 fbshipit-source-id: 623660e7047afcebf9f72d83f91f84ff6078090f --- folly/Expected.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/folly/Expected.h b/folly/Expected.h index 3de0a6d9..b4e63ee9 100644 --- a/folly/Expected.h +++ b/folly/Expected.h @@ -249,12 +249,11 @@ struct ExpectedUnion { union { Value value_; Error error_; - char ch_; + char ch_{}; }; - Which which_; + Which which_ = Which::eEmpty; - explicit constexpr ExpectedUnion(EmptyTag) noexcept - : ch_{}, which_(Which::eEmpty) {} + explicit constexpr ExpectedUnion(EmptyTag) noexcept {} template explicit constexpr ExpectedUnion(ValueTag, Vs&&... vs) noexcept( noexcept(Value(static_cast(vs)...))) -- 2.34.1