From 8752a27519e549460f6ac68e83bf67d511419606 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Sun, 14 Feb 2021 15:18:35 -0800 Subject: [PATCH] Kernel: Mark PhysicalAddress/VirtualAddress getters as [[nodiscard]] There is no reason to call a getter without observing the result, doing so indicates an error in the code. Mark these methods as [[nodiscard]] to find these cases. --- Kernel/PhysicalAddress.h | 14 +++++++------- Kernel/VirtualAddress.h | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Kernel/PhysicalAddress.h b/Kernel/PhysicalAddress.h index 1a8d9244f1..3c1bf0d9ef 100644 --- a/Kernel/PhysicalAddress.h +++ b/Kernel/PhysicalAddress.h @@ -37,18 +37,18 @@ public: { } - PhysicalAddress offset(FlatPtr o) const { return PhysicalAddress(m_address + o); } - FlatPtr get() const { return m_address; } + [[nodiscard]] PhysicalAddress offset(FlatPtr o) const { return PhysicalAddress(m_address + o); } + [[nodiscard]] FlatPtr get() const { return m_address; } void set(FlatPtr address) { m_address = address; } void mask(FlatPtr m) { m_address &= m; } - bool is_null() const { return m_address == 0; } + [[nodiscard]] bool is_null() const { return m_address == 0; } - u8* as_ptr() { return reinterpret_cast(m_address); } - const u8* as_ptr() const { return reinterpret_cast(m_address); } + [[nodiscard]] u8* as_ptr() { return reinterpret_cast(m_address); } + [[nodiscard]] const u8* as_ptr() const { return reinterpret_cast(m_address); } - PhysicalAddress page_base() const { return PhysicalAddress(m_address & 0xfffff000); } - FlatPtr offset_in_page() const { return PhysicalAddress(m_address & 0xfff).get(); } + [[nodiscard]] PhysicalAddress page_base() const { return PhysicalAddress(m_address & 0xfffff000); } + [[nodiscard]] FlatPtr offset_in_page() const { return PhysicalAddress(m_address & 0xfff).get(); } bool operator==(const PhysicalAddress& other) const { return m_address == other.m_address; } bool operator!=(const PhysicalAddress& other) const { return m_address != other.m_address; } diff --git a/Kernel/VirtualAddress.h b/Kernel/VirtualAddress.h index 78602aa8db..e05738bec5 100644 --- a/Kernel/VirtualAddress.h +++ b/Kernel/VirtualAddress.h @@ -42,11 +42,11 @@ public: { } - bool is_null() const { return m_address == 0; } - bool is_page_aligned() const { return (m_address & 0xfff) == 0; } + [[nodiscard]] bool is_null() const { return m_address == 0; } + [[nodiscard]] bool is_page_aligned() const { return (m_address & 0xfff) == 0; } - VirtualAddress offset(FlatPtr o) const { return VirtualAddress(m_address + o); } - FlatPtr get() const { return m_address; } + [[nodiscard]] VirtualAddress offset(FlatPtr o) const { return VirtualAddress(m_address + o); } + [[nodiscard]] FlatPtr get() const { return m_address; } void set(FlatPtr address) { m_address = address; } void mask(FlatPtr m) { m_address &= m; } @@ -57,10 +57,10 @@ public: bool operator==(const VirtualAddress& other) const { return m_address == other.m_address; } bool operator!=(const VirtualAddress& other) const { return m_address != other.m_address; } - u8* as_ptr() { return reinterpret_cast(m_address); } - const u8* as_ptr() const { return reinterpret_cast(m_address); } + [[nodiscard]] u8* as_ptr() { return reinterpret_cast(m_address); } + [[nodiscard]] const u8* as_ptr() const { return reinterpret_cast(m_address); } - VirtualAddress page_base() const { return VirtualAddress(m_address & 0xfffff000); } + [[nodiscard]] VirtualAddress page_base() const { return VirtualAddress(m_address & 0xfffff000); } private: FlatPtr m_address { 0 };