1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:07:45 +00:00

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