Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Self assignment #172

Merged
merged 8 commits into from
Sep 25, 2019
9 changes: 7 additions & 2 deletions include/mapbox/variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ class variant
#else
data_type data;
#endif

public:
VARIANT_INLINE variant() noexcept(std::is_nothrow_default_constructible<first_type>::value)
: type_index(sizeof...(Types)-1)
Expand Down Expand Up @@ -645,13 +645,18 @@ class variant
// move_assign uses move-construction via placement new.
noexcept(detail::conjunction<std::is_nothrow_move_constructible<Types>...>::value)
{
if (this == &other) { // playing safe in release mode, hit assertion in debug.
assert(false);
return *this;
}
move_assign(std::move(other));
return *this;
}

VARIANT_INLINE variant<Types...>& operator=(variant<Types...> const& other)
{
copy_assign(other);
if (this != &other)
copy_assign(other);
return *this;
}

Expand Down