X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FExpected.h;h=8f5d9a6496f5fd1a35d4d3574454462e2ba96f97;hb=51647aaa0ac0eaf8364f6dd643e0f615cd256819;hp=3de0a6d9b4230ef6d53408966ea701cca57c628f;hpb=a610249b9ea7c414810b1c0a12f9a81c13c834ec;p=folly.git diff --git a/folly/Expected.h b/folly/Expected.h index 3de0a6d9..8f5d9a64 100644 --- a/folly/Expected.h +++ b/folly/Expected.h @@ -1,5 +1,5 @@ /* - * Copyright 2016 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ */ /** - * Like folly::Optional, but can store a value *or* and error. + * Like folly::Optional, but can store a value *or* an error. * * @author Eric Niebler (eniebler@fb.com) */ @@ -32,8 +32,9 @@ #include #include #include -#include // for construct_in_place_t +#include #include +#include #define FOLLY_EXPECTED_ID(X) FB_CONCATENATE(FB_CONCATENATE(Folly, X), __LINE__) @@ -233,6 +234,11 @@ struct ExpectedStorage { Value&& value() && { return std::move(value_); } + // TODO (t17322426): remove when VS2015 support is deprecated + // VS2015 static analyzer incorrectly flags these as unreachable in certain + // circumstances. VS2017 does not have this problem on the same code. + FOLLY_PUSH_WARNING + FOLLY_MSVC_DISABLE_WARNING(4702) // unreachable code Error& error() & { return error_; } @@ -242,6 +248,7 @@ struct ExpectedStorage { Error&& error() && { return std::move(error_); } + FOLLY_POP_WARNING }; template @@ -249,12 +256,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)...))) @@ -446,7 +452,7 @@ struct ExpectedStorage this->which_ = Which::eError; } } - bool isThis(const ExpectedStorage* that) const { + bool isSelfAssign(const ExpectedStorage* that) const { return this == that; } constexpr bool isSelfAssign(const void*) const { @@ -528,6 +534,11 @@ struct ExpectedStorage { Value&& value() && { return std::move(value_); } + // TODO (t17322426): remove when VS2015 support is deprecated + // VS2015 static analyzer incorrectly flags these as unreachable in certain + // circumstances. VS2017 does not have this problem on the same code. + FOLLY_PUSH_WARNING + FOLLY_MSVC_DISABLE_WARNING(4702) // unreachable code Error& error() & { return error_; } @@ -537,6 +548,7 @@ struct ExpectedStorage { Error&& error() && { return std::move(error_); } + FOLLY_POP_WARNING }; namespace expected_detail_ExpectedHelper {