From 2a3ef377ec00e7c7d3f4c47614ab6baee727cd82 Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Mon, 10 Feb 2020 12:45:19 +0100 Subject: [PATCH] [lldb][NFC] Don't hide a bool in LibCxxOptional's OptionalFrontend::m_size m_size can only be 1 or 0 and indicates if the optional has a value. Calling it 'm_size', giving it a size_t data type and then also comparing indices against 'size' is very confusing. Let's just make this a bool. --- .../source/Plugins/Language/CPlusPlus/LibCxxOptional.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxOptional.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxOptional.cpp index e6de525e7d79..c0c819632851 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxOptional.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxOptional.cpp @@ -26,11 +26,12 @@ public: bool MightHaveChildren() override { return true; } bool Update() override; - size_t CalculateNumChildren() override { return m_size; } + size_t CalculateNumChildren() override { return m_has_value ? 1U : 0U; } ValueObjectSP GetChildAtIndex(size_t idx) override; private: - size_t m_size = 0; + /// True iff the option contains a value. + bool m_has_value = false; }; } // namespace @@ -44,13 +45,13 @@ bool OptionalFrontEnd::Update() { // __engaged_ is a bool flag and is true if the optional contains a value. // Converting it to unsigned gives us a size of 1 if it contains a value // and 0 if not. - m_size = engaged_sp->GetValueAsUnsigned(0); + m_has_value = engaged_sp->GetValueAsUnsigned(0) == 1; return false; } ValueObjectSP OptionalFrontEnd::GetChildAtIndex(size_t idx) { - if (idx >= m_size) + if (!m_has_value) return ValueObjectSP(); // __val_ contains the underlying value of an optional if it has one.