AK: Fix -Wconsumed warnings in Optional move-ctor and move-assign

Our protocol says we have to call has_value() before release_value().
The code was already safe, but the compiler had no way of knowing that.
This commit is contained in:
Andreas Kling 2019-08-07 07:17:52 +02:00
parent 0f7eece141
commit 60c25228ee

View file

@ -28,7 +28,7 @@ public:
Optional(Optional&& other)
: m_has_value(other.m_has_value)
{
if (m_has_value) {
if (other.has_value()) {
new (&m_storage) T(other.release_value());
other.m_has_value = false;
}
@ -62,9 +62,8 @@ public:
if (this != &other) {
clear();
m_has_value = other.m_has_value;
if (m_has_value) {
if (other.has_value())
new (&m_storage) T(other.release_value());
}
}
return *this;
}