From 60c25228ee27c81d5534cb3165ebb9267fd4fa1f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 7 Aug 2019 07:17:52 +0200 Subject: [PATCH] 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. --- AK/Optional.h | 5 ++--- 1 file 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; }