diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-08-07 07:17:52 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-08-07 07:17:52 +0200 |
commit | 60c25228ee27c81d5534cb3165ebb9267fd4fa1f (patch) | |
tree | c579605a4a7b1fae98d5da8cd1ffd15cac86439b /AK/Optional.h | |
parent | 0f7eece141e2fc2aa5100b06b5de1b05bed046f7 (diff) | |
download | serenity-60c25228ee27c81d5534cb3165ebb9267fd4fa1f.zip |
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.
Diffstat (limited to 'AK/Optional.h')
-rw-r--r-- | AK/Optional.h | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/AK/Optional.h b/AK/Optional.h index f53176e0e7..c9241e602f 100644 --- a/AK/Optional.h +++ b/AK/Optional.h @@ -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; } |