Commit 6e230a3f authored by Tom Jackson's avatar Tom Jackson Committed by Jordan DeLong

Optional bugfixes

Summary: Tests were run in 'opt', which masked issues alterted by asserts.

Test Plan: Unit tests

Reviewed By: delong.j@fb.com

FB internal diff: D611957
parent 368a5082
......@@ -90,12 +90,20 @@ class Optional : boost::totally_ordered<Optional<Value>,
}
Optional(const Optional& src) {
construct(src.value());
if (src.hasValue()) {
construct(src.value());
} else {
hasValue_ = false;
}
}
Optional(Optional&& src) {
construct(std::move(src.value()));
src.clear();
if (src.hasValue()) {
construct(std::move(src.value()));
src.clear();
} else {
hasValue_ = false;
}
}
/* implicit */ Optional(const None& empty)
......@@ -192,7 +200,7 @@ class Optional : boost::totally_ordered<Optional<Value>,
void clear() {
if (hasValue()) {
hasValue_ = false;
value().~Value();
value_.~Value();
}
}
......
......@@ -95,6 +95,15 @@ TEST(Optional, Simple) {
EXPECT_FALSE(opt);
}
TEST(Optional, EmptyConstruct) {
Optional<int> opt;
EXPECT_FALSE(opt);
Optional<int> test1(opt);
EXPECT_FALSE(test1);
Optional<int> test2(std::move(opt));
EXPECT_FALSE(test2);
}
TEST(Optional, Unique) {
Optional<unique_ptr<int>> opt;
......
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