Correct failure to set 'filled' flag in maybe_t constructors

This commit is contained in:
ridiculousfish 2018-03-10 02:10:40 -08:00
parent f1803feebf
commit 7764f27170
2 changed files with 10 additions and 3 deletions

View file

@ -4472,6 +4472,13 @@ void test_maybe() {
do_test(m2.missing_or_empty());
m2 = none();
do_test(m2.missing_or_empty());
maybe_t<std::string> m0 = none();
maybe_t<std::string> m3("hi");
maybe_t<std::string> m4 = m3;
do_test(m4 && *m4 == "hi");
maybe_t<std::string> m5 = m0;
do_test(!m5);
}
void test_layout_cache() {

View file

@ -40,16 +40,16 @@ class maybe_t {
/* implicit */ maybe_t(const T &v) : filled(true) { new (storage) T(v); }
// Copy constructor.
maybe_t(const maybe_t &v) {
maybe_t(const maybe_t &v) : filled(v.filled) {
if (v.filled) {
new (storage) T(v.value());
}
}
// Move constructor.
/* implicit */ maybe_t(maybe_t &&v) {
/* implicit */ maybe_t(maybe_t &&v) : filled(v.filled) {
if (v.filled) {
*this = std::move(v.value());
new (storage) T(std::move(v.value()));
}
}