Commit 3fb4ba1d authored by Orvid King's avatar Orvid King Committed by Facebook Github Bot

Revert D15057633: [folly] allow conversion from nullptr to folly::Optional<bool>

Differential Revision:
D15057633

Original commit changeset: 6ba47a57a78e

fbshipit-source-id: 1ae1384e5e9de3f2e80571b626a41ef6e713b3b2
parent cad67038
......@@ -133,6 +133,25 @@ class Optional {
construct(newValue);
}
/**
* Explicitly disallow converting nullptr to non-pointer
* types. Optional used to support initialization from nullptr as if
* it were folly::none. Without this constructor,
* folly::Optional<bool> could be constructed from nullptr,
* producing {false} instead of {}. This would be a change in
* behavior from the old code, so explicitly disallow it. Note that
* std::optional<bool> can be constructed from nullptr, also
* producing {false}.
*
* This constructor is temporary and should be removed when all call
* sites are fixed.
*/
template <typename Null = std::nullptr_t>
/* implicit */
Optional(typename std::enable_if<
std::is_convertible<Null, Value>::value,
Null>::type) noexcept = delete;
template <typename... Args>
constexpr explicit Optional(in_place_t, Args&&... args) noexcept(
std::is_nothrow_constructible<Value, Args...>::value)
......
......@@ -667,18 +667,6 @@ TEST(Optional, InitializerListConstruct) {
std::ignore = optional;
}
TEST(Optional, ConversionFromNullptr) {
// Match the behavior of std::optional
static constexpr void* null = nullptr;
folly::Optional<bool> o1{null};
folly::Optional<bool> o2(null);
folly::Optional<bool> o3 = null;
EXPECT_EQ(false, o1.value());
EXPECT_EQ(false, o2.value());
EXPECT_EQ(false, o3.value());
}
TEST(Optional, TestDisambiguationMakeOptionalVariants) {
{
auto optional = make_optional<int>(1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment