From: Philip Pronin Date: Tue, 25 Oct 2016 06:27:16 +0000 (-0700) Subject: fix Expected<..., eUnion> move / copy ctor X-Git-Tag: v2016.10.31.00~8 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=c1ead85dff393f6e5c356073375bc955e1714403;p=folly.git 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 --- 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)...)))