/*
- * 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.
*/
/**
- * 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)
*/
#include <folly/Likely.h>
#include <folly/Portability.h>
#include <folly/Preprocessor.h>
-#include <folly/Traits.h> // for construct_in_place_t
+#include <folly/Traits.h>
#include <folly/Unit.h>
+#include <folly/Utility.h>
#define FOLLY_EXPECTED_ID(X) FB_CONCATENATE(FB_CONCATENATE(Folly, X), __LINE__)
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_;
}
Error&& error() && {
return std::move(error_);
}
+ FOLLY_POP_WARNING
};
template <class Value, class Error>
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 <class... Vs>
explicit constexpr ExpectedUnion(ValueTag, Vs&&... vs) noexcept(
noexcept(Value(static_cast<Vs&&>(vs)...)))
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 {
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_;
}
Error&& error() && {
return std::move(error_);
}
+ FOLLY_POP_WARNING
};
namespace expected_detail_ExpectedHelper {