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:
parent
0f7eece141
commit
60c25228ee
1 changed files with 2 additions and 3 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue