diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2014-10-18 13:58:19 -0700 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2014-10-18 14:23:21 -0700 |
commit | d7e5119b4c64a960ae66fdc0478e9658c9ebbf63 (patch) | |
tree | 2bc4f78a33c449272fffc94e21dbca9b5ce4ae03 /src/compat/option_test.cpp | |
parent | 8eea85618c4a070fda6257f2be5280f9684c93c6 (diff) | |
download | tmwa-d7e5119b4c64a960ae66fdc0478e9658c9ebbf63.tar.gz tmwa-d7e5119b4c64a960ae66fdc0478e9658c9ebbf63.tar.bz2 tmwa-d7e5119b4c64a960ae66fdc0478e9658c9ebbf63.tar.xz tmwa-d7e5119b4c64a960ae66fdc0478e9658c9ebbf63.zip |
Fix bug where Option destroys too much
Diffstat (limited to 'src/compat/option_test.cpp')
-rw-r--r-- | src/compat/option_test.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/compat/option_test.cpp b/src/compat/option_test.cpp index b963a29..ac95424 100644 --- a/src/compat/option_test.cpp +++ b/src/compat/option_test.cpp @@ -117,6 +117,41 @@ TEST(Option, customrepr) } } +TEST(Option, destruct) +{ + struct BugCheck + { + bool *destroyed; + + BugCheck(bool *d) + : destroyed(d) + {} + BugCheck(BugCheck&& r) + : destroyed(r.destroyed) + { + r.destroyed = nullptr; + } + BugCheck& operator = (BugCheck&& r) + { + std::swap(destroyed, r.destroyed); + return *this; + } + ~BugCheck() + { + if (!destroyed) + return; + if (*destroyed) + abort(); + *destroyed = true; + } + }; + + bool destroyed = false; + + Option<BugCheck> bug = Some(BugCheck(&destroyed)); + bug = None; +} + TEST(Option, def) { struct Tracked |