From df7248039553b3ebd338380c3ef0428b0e046e79 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 14 Aug 2020 09:38:45 -0400 Subject: common: Make use of [[nodiscard]] where applicable Now that clang-format makes [[nodiscard]] attributes format sensibly, we can apply them to several functions within the common library to allow the compiler to complain about any misuses of the functions. --- src/common/common_funcs.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/common/common_funcs.h') diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 88cf5250a..98421bced 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h @@ -53,14 +53,14 @@ __declspec(dllimport) void __stdcall DebugBreak(void); // Call directly after the command or use the error num. // This function might change the error code. // Defined in Misc.cpp. -std::string GetLastErrorMsg(); +[[nodiscard]] std::string GetLastErrorMsg(); #define DECLARE_ENUM_FLAG_OPERATORS(type) \ - constexpr type operator|(type a, type b) noexcept { \ + [[nodiscard]] constexpr type operator|(type a, type b) noexcept { \ using T = std::underlying_type_t; \ return static_cast(static_cast(a) | static_cast(b)); \ } \ - constexpr type operator&(type a, type b) noexcept { \ + [[nodiscard]] constexpr type operator&(type a, type b) noexcept { \ using T = std::underlying_type_t; \ return static_cast(static_cast(a) & static_cast(b)); \ } \ @@ -74,22 +74,22 @@ std::string GetLastErrorMsg(); a = static_cast(static_cast(a) & static_cast(b)); \ return a; \ } \ - constexpr type operator~(type key) noexcept { \ + [[nodiscard]] constexpr type operator~(type key) noexcept { \ using T = std::underlying_type_t; \ return static_cast(~static_cast(key)); \ } \ - constexpr bool True(type key) noexcept { \ + [[nodiscard]] constexpr bool True(type key) noexcept { \ using T = std::underlying_type_t; \ return static_cast(key) != 0; \ } \ - constexpr bool False(type key) noexcept { \ + [[nodiscard]] constexpr bool False(type key) noexcept { \ using T = std::underlying_type_t; \ return static_cast(key) == 0; \ } namespace Common { -constexpr u32 MakeMagic(char a, char b, char c, char d) { +[[nodiscard]] constexpr u32 MakeMagic(char a, char b, char c, char d) { return u32(a) | u32(b) << 8 | u32(c) << 16 | u32(d) << 24; } -- cgit v1.2.3