diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2014-08-12 10:09:24 -0700 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2014-08-25 17:58:12 -0700 |
commit | 31e906c1fbaf3bc9128138302d8db549e87769a7 (patch) | |
tree | 661eb57b673cdf16528aefd6b51a53b5522e79c9 /src/sexpr | |
parent | 569b0db91ede28450e2657ea5a09e713fb6495ef (diff) | |
download | tmwa-31e906c1fbaf3bc9128138302d8db549e87769a7.tar.gz tmwa-31e906c1fbaf3bc9128138302d8db549e87769a7.tar.bz2 tmwa-31e906c1fbaf3bc9128138302d8db549e87769a7.tar.xz tmwa-31e906c1fbaf3bc9128138302d8db549e87769a7.zip |
Bust the last evil union
Diffstat (limited to 'src/sexpr')
-rw-r--r-- | src/sexpr/variant.tcc | 2 | ||||
-rw-r--r-- | src/sexpr/variant_test.cpp | 36 |
2 files changed, 36 insertions, 2 deletions
diff --git a/src/sexpr/variant.tcc b/src/sexpr/variant.tcc index a2ab7c0..1f7df03 100644 --- a/src/sexpr/variant.tcc +++ b/src/sexpr/variant.tcc @@ -228,7 +228,7 @@ namespace sexpr Variant<D, T...>& Variant<D, T...>::operator = (const Variant& r) { if (state == r.state) - apply(Void(), CopyAssign<D, T...>(this), r); + apply(Void(), CopyAssign<D, T...>(&data), r); else { do_destruct(); diff --git a/src/sexpr/variant_test.cpp b/src/sexpr/variant_test.cpp index 5a75780..bc378aa 100644 --- a/src/sexpr/variant_test.cpp +++ b/src/sexpr/variant_test.cpp @@ -115,9 +115,43 @@ TEST(variant, match) } } -TEST(variant, copymove) +TEST(variant, copymove1) { sexpr::Variant<Qux> moveonly(Qux(3)); (void)moveonly; } + +TEST(variant, copymove2) +{ + struct Move + { + Move() = default; + Move(Move&&) = default; + Move(const Move&) = delete; + Move& operator = (Move&&) = default; + Move& operator = (const Move&) = delete; + ~Move() = default; + }; + struct Copy + { + Copy() = default; + Copy(Copy&&) = default; + Copy(const Copy&) = default; + Copy& operator = (Copy&&) = default; + Copy& operator = (const Copy&) = default; + ~Copy() = default; + }; + + using VarMv = sexpr::Variant<Move>; + using VarCp = sexpr::Variant<Copy>; + + VarMv mv1; + VarMv mv3 = std::move(mv1); + mv1 = std::move(mv3); + VarCp cp1; + VarCp cp2 = cp1; + VarCp cp3 = std::move(cp1); + cp1 = cp2; + cp1 = std::move(cp3); +} } // namespace tmwa |