From f6b543886c42def34369451927be6dbf8d3e1b4f Mon Sep 17 00:00:00 2001 From: Tobias Date: Mon, 31 Aug 2020 21:06:16 +0200 Subject: [PATCH] Port yuzu-emu/yuzu#4528: "common: Make use of [[nodiscard]] where applicable" (#5535) Co-authored-by: LC <712067+lioncash@users.noreply.github.com> --- .../configuration/configure_input.cpp | 51 ++--- src/common/alignment.h | 4 +- src/common/bit_field.h | 12 +- src/common/cityhash.h | 23 +- src/common/color.h | 34 +-- src/common/common_funcs.h | 2 +- src/common/detached_tasks.cpp | 3 +- src/common/file_util.h | 61 +++--- src/common/math_util.h | 12 +- src/common/param_package.h | 10 +- src/common/quaternion.h | 15 +- src/common/ring_buffer.h | 4 +- src/common/string_util.h | 28 +-- src/common/telemetry.h | 12 +- src/common/thread_queue_list.h | 14 +- src/common/threadsafe_queue.h | 12 +- src/common/timer.h | 16 +- src/common/vector_math.h | 204 +++++++++--------- src/common/zstd_compression.h | 7 +- src/core/hle/service/cecd/cecd.cpp | 3 +- src/core/movie.h | 4 +- src/input_common/udp/client.cpp | 6 +- src/tests/core/arm/arm_test_common.cpp | 3 +- src/tests/core/hle/kernel/hle_ipc.cpp | 6 +- src/tests/core/memory/memory.cpp | 3 +- 25 files changed, 284 insertions(+), 265 deletions(-) diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp index 74ed5d7bd..18c56366f 100644 --- a/src/citra_qt/configuration/configure_input.cpp +++ b/src/citra_qt/configuration/configure_input.cpp @@ -164,15 +164,16 @@ ConfigureInput::ConfigureInput(QWidget* parent) continue; button_map[button_id]->setContextMenuPolicy(Qt::CustomContextMenu); connect(button_map[button_id], &QPushButton::clicked, [=]() { - HandleClick(button_map[button_id], - [=](const Common::ParamPackage& params) { - buttons_param[button_id] = params; - // If the user closes the dialog, the changes are reverted in - // `GMainWindow::OnConfigure()` - ApplyConfiguration(); - Settings::SaveProfile(ui->profile->currentIndex()); - }, - InputCommon::Polling::DeviceType::Button); + HandleClick( + button_map[button_id], + [=](const Common::ParamPackage& params) { + buttons_param[button_id] = params; + // If the user closes the dialog, the changes are reverted in + // `GMainWindow::OnConfigure()` + ApplyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }, + InputCommon::Polling::DeviceType::Button); }); connect(button_map[button_id], &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { @@ -201,14 +202,15 @@ ConfigureInput::ConfigureInput(QWidget* parent) analog_map_buttons[analog_id][sub_button_id]->setContextMenuPolicy( Qt::CustomContextMenu); connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::clicked, [=]() { - HandleClick(analog_map_buttons[analog_id][sub_button_id], - [=](const Common::ParamPackage& params) { - SetAnalogButton(params, analogs_param[analog_id], - analog_sub_buttons[sub_button_id]); - ApplyConfiguration(); - Settings::SaveProfile(ui->profile->currentIndex()); - }, - InputCommon::Polling::DeviceType::Button); + HandleClick( + analog_map_buttons[analog_id][sub_button_id], + [=](const Common::ParamPackage& params) { + SetAnalogButton(params, analogs_param[analog_id], + analog_sub_buttons[sub_button_id]); + ApplyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }, + InputCommon::Polling::DeviceType::Button); }); connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { @@ -239,13 +241,14 @@ ConfigureInput::ConfigureInput(QWidget* parent) tr("After pressing OK, first move your joystick horizontally, " "and then vertically."), QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) { - HandleClick(analog_map_stick[analog_id], - [=](const Common::ParamPackage& params) { - analogs_param[analog_id] = params; - ApplyConfiguration(); - Settings::SaveProfile(ui->profile->currentIndex()); - }, - InputCommon::Polling::DeviceType::Analog); + HandleClick( + analog_map_stick[analog_id], + [=](const Common::ParamPackage& params) { + analogs_param[analog_id] = params; + ApplyConfiguration(); + Settings::SaveProfile(ui->profile->currentIndex()); + }, + InputCommon::Polling::DeviceType::Analog); } }); connect(analog_map_deadzone_and_modifier_slider[analog_id], &QSlider::valueChanged, [=] { diff --git a/src/common/alignment.h b/src/common/alignment.h index 92dec59c1..64fafd2e8 100644 --- a/src/common/alignment.h +++ b/src/common/alignment.h @@ -8,7 +8,7 @@ namespace Common { template -constexpr T AlignUp(T value, std::size_t size) { +[[nodiscard]] constexpr T AlignUp(T value, std::size_t size) { static_assert(std::is_unsigned_v, "T must be an unsigned value."); auto mod{value % size}; value -= mod; @@ -16,7 +16,7 @@ constexpr T AlignUp(T value, std::size_t size) { } template -constexpr T AlignDown(T value, std::size_t size) { +[[nodiscard]] constexpr T AlignDown(T value, std::size_t size) { static_assert(std::is_unsigned_v, "T must be an unsigned value."); return static_cast(value - value % size); } diff --git a/src/common/bit_field.h b/src/common/bit_field.h index 8131d1f95..4ec3af1af 100644 --- a/src/common/bit_field.h +++ b/src/common/bit_field.h @@ -135,8 +135,8 @@ public: * containing several bitfields can be assembled by formatting each of their values and ORing * the results together. */ - static constexpr FORCE_INLINE StorageType FormatValue(const T& value) { - return ((StorageType)value << position) & mask; + [[nodiscard]] static constexpr StorageType FormatValue(const T& value) { + return (static_cast(value) << position) & mask; } /** @@ -144,7 +144,7 @@ public: * (such as Value() or operator T), but this can be used to extract a value from a bitfield * union in a constexpr context. */ - static constexpr FORCE_INLINE T ExtractValue(const StorageType& storage) { + [[nodiscard]] static constexpr T ExtractValue(const StorageType& storage) { if constexpr (std::numeric_limits::is_signed) { std::size_t shift = 8 * sizeof(T) - bits; return static_cast(static_cast(storage << (shift - position)) >> @@ -168,7 +168,7 @@ public: constexpr BitField(BitField&&) noexcept = default; constexpr BitField& operator=(BitField&&) noexcept = default; - constexpr operator T() const { + [[nodiscard]] constexpr operator T() const { return Value(); } @@ -176,11 +176,11 @@ public: storage = (static_cast(storage) & ~mask) | FormatValue(value); } - constexpr T Value() const { + [[nodiscard]] constexpr T Value() const { return ExtractValue(storage); } - constexpr explicit operator bool() const { + [[nodiscard]] constexpr explicit operator bool() const { return Value() != 0; } diff --git a/src/common/cityhash.h b/src/common/cityhash.h index 4b94f8e18..a00804e01 100644 --- a/src/common/cityhash.h +++ b/src/common/cityhash.h @@ -61,42 +61,43 @@ #pragma once +#include +#include #include -#include -#include // for std::size_t. namespace Common { -typedef std::pair uint128; +using uint128 = std::pair; -inline uint64_t Uint128Low64(const uint128& x) { +[[nodiscard]] inline uint64_t Uint128Low64(const uint128& x) { return x.first; } -inline uint64_t Uint128High64(const uint128& x) { +[[nodiscard]] inline uint64_t Uint128High64(const uint128& x) { return x.second; } // Hash function for a byte array. -uint64_t CityHash64(const char* buf, std::size_t len); +[[nodiscard]] uint64_t CityHash64(const char* buf, std::size_t len); // Hash function for a byte array. For convenience, a 64-bit seed is also // hashed into the result. -uint64_t CityHash64WithSeed(const char* buf, std::size_t len, uint64_t seed); +[[nodiscard]] uint64_t CityHash64WithSeed(const char* buf, std::size_t len, uint64_t seed); // Hash function for a byte array. For convenience, two seeds are also // hashed into the result. -uint64_t CityHash64WithSeeds(const char* buf, std::size_t len, uint64_t seed0, uint64_t seed1); +[[nodiscard]] uint64_t CityHash64WithSeeds(const char* buf, std::size_t len, uint64_t seed0, + uint64_t seed1); // Hash function for a byte array. -uint128 CityHash128(const char* s, std::size_t len); +[[nodiscard]] uint128 CityHash128(const char* s, std::size_t len); // Hash function for a byte array. For convenience, a 128-bit seed is also // hashed into the result. -uint128 CityHash128WithSeed(const char* s, std::size_t len, uint128 seed); +[[nodiscard]] uint128 CityHash128WithSeed(const char* s, std::size_t len, uint128 seed); // Hash 128 input bits down to 64 bits of output. // This is intended to be a reasonably good hash function. -inline uint64_t Hash128to64(const uint128& x) { +[[nodiscard]] inline uint64_t Hash128to64(const uint128& x) { // Murmur-inspired hashing. const uint64_t kMul = 0x9ddfea08eb382d69ULL; uint64_t a = (Uint128Low64(x) ^ Uint128High64(x)) * kMul; diff --git a/src/common/color.h b/src/common/color.h index 3a2222077..381d6332e 100644 --- a/src/common/color.h +++ b/src/common/color.h @@ -13,42 +13,42 @@ namespace Color { /// Convert a 1-bit color component to 8 bit -constexpr u8 Convert1To8(u8 value) { +[[nodiscard]] constexpr u8 Convert1To8(u8 value) { return value * 255; } /// Convert a 4-bit color component to 8 bit -constexpr u8 Convert4To8(u8 value) { +[[nodiscard]] constexpr u8 Convert4To8(u8 value) { return (value << 4) | value; } /// Convert a 5-bit color component to 8 bit -constexpr u8 Convert5To8(u8 value) { +[[nodiscard]] constexpr u8 Convert5To8(u8 value) { return (value << 3) | (value >> 2); } /// Convert a 6-bit color component to 8 bit -constexpr u8 Convert6To8(u8 value) { +[[nodiscard]] constexpr u8 Convert6To8(u8 value) { return (value << 2) | (value >> 4); } /// Convert a 8-bit color component to 1 bit -constexpr u8 Convert8To1(u8 value) { +[[nodiscard]] constexpr u8 Convert8To1(u8 value) { return value >> 7; } /// Convert a 8-bit color component to 4 bit -constexpr u8 Convert8To4(u8 value) { +[[nodiscard]] constexpr u8 Convert8To4(u8 value) { return value >> 4; } /// Convert a 8-bit color component to 5 bit -constexpr u8 Convert8To5(u8 value) { +[[nodiscard]] constexpr u8 Convert8To5(u8 value) { return value >> 3; } /// Convert a 8-bit color component to 6 bit -constexpr u8 Convert8To6(u8 value) { +[[nodiscard]] constexpr u8 Convert8To6(u8 value) { return value >> 2; } @@ -57,7 +57,7 @@ constexpr u8 Convert8To6(u8 value) { * @param bytes Pointer to encoded source color * @return Result color decoded as Common::Vec4 */ -inline Common::Vec4 DecodeRGBA8(const u8* bytes) { +[[nodiscard]] inline Common::Vec4 DecodeRGBA8(const u8* bytes) { return {bytes[3], bytes[2], bytes[1], bytes[0]}; } @@ -66,7 +66,7 @@ inline Common::Vec4 DecodeRGBA8(const u8* bytes) { * @param bytes Pointer to encoded source color * @return Result color decoded as Common::Vec4 */ -inline Common::Vec4 DecodeRGB8(const u8* bytes) { +[[nodiscard]] inline Common::Vec4 DecodeRGB8(const u8* bytes) { return {bytes[2], bytes[1], bytes[0], 255}; } @@ -75,7 +75,7 @@ inline Common::Vec4 DecodeRGB8(const u8* bytes) { * @param bytes Pointer to encoded source color * @return Result color decoded as Common::Vec4 */ -inline Common::Vec4 DecodeRG8(const u8* bytes) { +[[nodiscard]] inline Common::Vec4 DecodeRG8(const u8* bytes) { return {bytes[1], bytes[0], 0, 255}; } @@ -84,7 +84,7 @@ inline Common::Vec4 DecodeRG8(const u8* bytes) { * @param bytes Pointer to encoded source color * @return Result color decoded as Common::Vec4 */ -inline Common::Vec4 DecodeRGB565(const u8* bytes) { +[[nodiscard]] inline Common::Vec4 DecodeRGB565(const u8* bytes) { u16_le pixel; std::memcpy(&pixel, bytes, sizeof(pixel)); return {Convert5To8((pixel >> 11) & 0x1F), Convert6To8((pixel >> 5) & 0x3F), @@ -96,7 +96,7 @@ inline Common::Vec4 DecodeRGB565(const u8* bytes) { * @param bytes Pointer to encoded source color * @return Result color decoded as Common::Vec4 */ -inline Common::Vec4 DecodeRGB5A1(const u8* bytes) { +[[nodiscard]] inline Common::Vec4 DecodeRGB5A1(const u8* bytes) { u16_le pixel; std::memcpy(&pixel, bytes, sizeof(pixel)); return {Convert5To8((pixel >> 11) & 0x1F), Convert5To8((pixel >> 6) & 0x1F), @@ -108,7 +108,7 @@ inline Common::Vec4 DecodeRGB5A1(const u8* bytes) { * @param bytes Pointer to encoded source color * @return Result color decoded as Common::Vec4 */ -inline Common::Vec4 DecodeRGBA4(const u8* bytes) { +[[nodiscard]] inline Common::Vec4 DecodeRGBA4(const u8* bytes) { u16_le pixel; std::memcpy(&pixel, bytes, sizeof(pixel)); return {Convert4To8((pixel >> 12) & 0xF), Convert4To8((pixel >> 8) & 0xF), @@ -120,7 +120,7 @@ inline Common::Vec4 DecodeRGBA4(const u8* bytes) { * @param bytes Pointer to encoded source value * @return Depth value as an u32 */ -inline u32 DecodeD16(const u8* bytes) { +[[nodiscard]] inline u32 DecodeD16(const u8* bytes) { u16_le data; std::memcpy(&data, bytes, sizeof(data)); return data; @@ -131,7 +131,7 @@ inline u32 DecodeD16(const u8* bytes) { * @param bytes Pointer to encoded source value * @return Depth value as an u32 */ -inline u32 DecodeD24(const u8* bytes) { +[[nodiscard]] inline u32 DecodeD24(const u8* bytes) { return (bytes[2] << 16) | (bytes[1] << 8) | bytes[0]; } @@ -140,7 +140,7 @@ inline u32 DecodeD24(const u8* bytes) { * @param bytes Pointer to encoded source values * @return Resulting values stored as a Common::Vec2 */ -inline Common::Vec2 DecodeD24S8(const u8* bytes) { +[[nodiscard]] inline Common::Vec2 DecodeD24S8(const u8* bytes) { return {static_cast((bytes[2] << 16) | (bytes[1] << 8) | bytes[0]), bytes[3]}; } diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index baf145901..1420675d4 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h @@ -57,4 +57,4 @@ __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(); diff --git a/src/common/detached_tasks.cpp b/src/common/detached_tasks.cpp index f268d6021..f2b4939df 100644 --- a/src/common/detached_tasks.cpp +++ b/src/common/detached_tasks.cpp @@ -34,8 +34,7 @@ void DetachedTasks::AddTask(std::function task) { std::unique_lock lock{instance->mutex}; --instance->count; std::notify_all_at_thread_exit(instance->cv, std::move(lock)); - }) - .detach(); + }).detach(); } } // namespace Common diff --git a/src/common/file_util.h b/src/common/file_util.h index b7cbfdafd..6fa14315c 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -91,19 +91,19 @@ private: }; // Returns true if file filename exists -bool Exists(const std::string& filename); +[[nodiscard]] bool Exists(const std::string& filename); // Returns true if filename is a directory -bool IsDirectory(const std::string& filename); +[[nodiscard]] bool IsDirectory(const std::string& filename); // Returns the size of filename (64bit) -u64 GetSize(const std::string& filename); +[[nodiscard]] u64 GetSize(const std::string& filename); // Overloaded GetSize, accepts file descriptor -u64 GetSize(const int fd); +[[nodiscard]] u64 GetSize(int fd); // Overloaded GetSize, accepts FILE* -u64 GetSize(FILE* f); +[[nodiscard]] u64 GetSize(FILE* f); // Returns true if successful, or path already exists. bool CreateDir(const std::string& filename); @@ -170,7 +170,7 @@ void GetAllFilesFromNestedEntries(FSTEntry& directory, std::vector& ou bool DeleteDirRecursively(const std::string& directory, unsigned int recursion = 256); // Returns the current directory -std::optional GetCurrentDir(); +[[nodiscard]] std::optional GetCurrentDir(); // Create directory and copy contents (does not overwrite existing files) void CopyDir(const std::string& source_path, const std::string& dest_path); @@ -184,18 +184,18 @@ void SetCurrentRomPath(const std::string& path); // Returns a pointer to a string with a Citra data dir in the user's home // directory. To be used in "multi-user" mode (that is, installed). -const std::string& GetUserPath(UserPath path); +[[nodiscard]] const std::string& GetUserPath(UserPath path); // Returns the path to where the sys file are -std::string GetSysDirectory(); +[[nodiscard]] std::string GetSysDirectory(); #ifdef __APPLE__ -std::string GetBundleDirectory(); +[[nodiscard]] std::string GetBundleDirectory(); #endif #ifdef _WIN32 -const std::string& GetExeDirectory(); -std::string AppDataRoamingDirectory(); +[[nodiscard]] const std::string& GetExeDirectory(); +[[nodiscard]] std::string AppDataRoamingDirectory(); #endif std::size_t WriteStringToFile(bool text_file, const std::string& filename, std::string_view str); @@ -214,38 +214,45 @@ void SplitFilename83(const std::string& filename, std::array& short_nam // Splits the path on '/' or '\' and put the components into a vector // i.e. "C:\Users\Yuzu\Documents\save.bin" becomes {"C:", "Users", "Yuzu", "Documents", "save.bin" } -std::vector SplitPathComponents(std::string_view filename); +[[nodiscard]] std::vector SplitPathComponents(std::string_view filename); // Gets all of the text up to the last '/' or '\' in the path. -std::string_view GetParentPath(std::string_view path); +[[nodiscard]] std::string_view GetParentPath(std::string_view path); // Gets all of the text after the first '/' or '\' in the path. -std::string_view GetPathWithoutTop(std::string_view path); +[[nodiscard]] std::string_view GetPathWithoutTop(std::string_view path); // Gets the filename of the path -std::string_view GetFilename(std::string_view path); +[[nodiscard]] std::string_view GetFilename(std::string_view path); // Gets the extension of the filename -std::string_view GetExtensionFromFilename(std::string_view name); +[[nodiscard]] std::string_view GetExtensionFromFilename(std::string_view name); // Removes the final '/' or '\' if one exists -std::string_view RemoveTrailingSlash(std::string_view path); +[[nodiscard]] std::string_view RemoveTrailingSlash(std::string_view path); // Creates a new vector containing indices [first, last) from the original. template -std::vector SliceVector(const std::vector& vector, std::size_t first, std::size_t last) { - if (first >= last) +[[nodiscard]] std::vector SliceVector(const std::vector& vector, std::size_t first, + std::size_t last) { + if (first >= last) { return {}; + } last = std::min(last, vector.size()); return std::vector(vector.begin() + first, vector.begin() + first + last); } -enum class DirectorySeparator { ForwardSlash, BackwardSlash, PlatformDefault }; +enum class DirectorySeparator { + ForwardSlash, + BackwardSlash, + PlatformDefault, +}; // Removes trailing slash, makes all '\\' into '/', and removes duplicate '/'. Makes '/' into '\\' // depending if directory_separator is BackwardSlash or PlatformDefault and running on windows -std::string SanitizePath(std::string_view path, - DirectorySeparator directory_separator = DirectorySeparator::ForwardSlash); +[[nodiscard]] std::string SanitizePath( + std::string_view path, + DirectorySeparator directory_separator = DirectorySeparator::ForwardSlash); // simple wrapper for cstdlib file functions to // hopefully will make error checking easier @@ -314,21 +321,21 @@ public: return WriteArray(str.data(), str.length()); } - bool IsOpen() const { + [[nodiscard]] bool IsOpen() const { return nullptr != m_file; } // m_good is set to false when a read, write or other function fails - bool IsGood() const { + [[nodiscard]] bool IsGood() const { return m_good; } - explicit operator bool() const { + [[nodiscard]] explicit operator bool() const { return IsGood(); } bool Seek(s64 off, int origin); - u64 Tell() const; - u64 GetSize() const; + [[nodiscard]] u64 Tell() const; + [[nodiscard]] u64 GetSize() const; bool Resize(u64 size); bool Flush(); diff --git a/src/common/math_util.h b/src/common/math_util.h index d6c35ee89..382d0197d 100644 --- a/src/common/math_util.h +++ b/src/common/math_util.h @@ -23,25 +23,25 @@ struct Rectangle { constexpr Rectangle(T left, T top, T right, T bottom) : left(left), top(top), right(right), bottom(bottom) {} - T GetWidth() const { + [[nodiscard]] T GetWidth() const { return std::abs(static_cast>(right - left)); } - T GetHeight() const { + [[nodiscard]] T GetHeight() const { return std::abs(static_cast>(bottom - top)); } - Rectangle TranslateX(const T x) const { + [[nodiscard]] Rectangle TranslateX(const T x) const { return Rectangle{left + x, top, right + x, bottom}; } - Rectangle TranslateY(const T y) const { + [[nodiscard]] Rectangle TranslateY(const T y) const { return Rectangle{left, top + y, right, bottom + y}; } - Rectangle Scale(const float s) const { + [[nodiscard]] Rectangle Scale(const float s) const { return Rectangle{left, top, static_cast(left + GetWidth() * s), static_cast(top + GetHeight() * s)}; } }; template -Rectangle(T, T, T, T)->Rectangle; +Rectangle(T, T, T, T) -> Rectangle; } // namespace Common diff --git a/src/common/param_package.h b/src/common/param_package.h index 1fffb5035..7db597b42 100644 --- a/src/common/param_package.h +++ b/src/common/param_package.h @@ -24,14 +24,14 @@ public: ParamPackage& operator=(const ParamPackage& other) = default; ParamPackage& operator=(ParamPackage&& other) = default; - std::string Serialize() const; - std::string Get(const std::string& key, const std::string& default_value) const; - int Get(const std::string& key, int default_value) const; - float Get(const std::string& key, float default_value) const; + [[nodiscard]] std::string Serialize() const; + [[nodiscard]] std::string Get(const std::string& key, const std::string& default_value) const; + [[nodiscard]] int Get(const std::string& key, int default_value) const; + [[nodiscard]] float Get(const std::string& key, float default_value) const; void Set(const std::string& key, std::string value); void Set(const std::string& key, int value); void Set(const std::string& key, float value); - bool Has(const std::string& key) const; + [[nodiscard]] bool Has(const std::string& key) const; void Erase(const std::string& key); void Clear(); diff --git a/src/common/quaternion.h b/src/common/quaternion.h index 370198ae0..da44f35cd 100644 --- a/src/common/quaternion.h +++ b/src/common/quaternion.h @@ -14,35 +14,36 @@ public: Vec3 xyz; T w{}; - Quaternion Inverse() const { + [[nodiscard]] Quaternion Inverse() const { return {-xyz, w}; } - Quaternion operator+(const Quaternion& other) const { + [[nodiscard]] Quaternion operator+(const Quaternion& other) const { return {xyz + other.xyz, w + other.w}; } - Quaternion operator-(const Quaternion& other) const { + [[nodiscard]] Quaternion operator-(const Quaternion& other) const { return {xyz - other.xyz, w - other.w}; } - Quaternion operator*(const Quaternion& other) const { + [[nodiscard]] Quaternion operator*( + const Quaternion& other) const { return {xyz * other.w + other.xyz * w + Cross(xyz, other.xyz), w * other.w - Dot(xyz, other.xyz)}; } - Quaternion Normalized() const { + [[nodiscard]] Quaternion Normalized() const { T length = std::sqrt(xyz.Length2() + w * w); return {xyz / length, w / length}; } }; template -auto QuaternionRotate(const Quaternion& q, const Vec3& v) { +[[nodiscard]] auto QuaternionRotate(const Quaternion& q, const Vec3& v) { return v + 2 * Cross(q.xyz, Cross(q.xyz, v) + v * q.w); } -inline Quaternion MakeQuaternion(const Vec3& axis, float angle) { +[[nodiscard]] inline Quaternion MakeQuaternion(const Vec3& axis, float angle) { return {axis * std::sin(angle / 2), std::cos(angle / 2)}; } diff --git a/src/common/ring_buffer.h b/src/common/ring_buffer.h index bb94b898b..080059058 100644 --- a/src/common/ring_buffer.h +++ b/src/common/ring_buffer.h @@ -91,12 +91,12 @@ public: } /// @returns Number of slots used - std::size_t Size() const { + [[nodiscard]] std::size_t Size() const { return m_write_index.load() - m_read_index.load(); } /// @returns Maximum size of ring buffer - constexpr std::size_t Capacity() const { + [[nodiscard]] constexpr std::size_t Capacity() const { return capacity; } diff --git a/src/common/string_util.h b/src/common/string_util.h index 8c1894621..2c454bb7b 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -14,17 +14,17 @@ namespace Common { /// Make a string lowercase -std::string ToLower(std::string str); +[[nodiscard]] std::string ToLower(std::string str); /// Make a string uppercase -std::string ToUpper(std::string str); +[[nodiscard]] std::string ToUpper(std::string str); -std::string StripSpaces(const std::string& s); -std::string StripQuotes(const std::string& s); +[[nodiscard]] std::string StripSpaces(const std::string& s); +[[nodiscard]] std::string StripQuotes(const std::string& s); -std::string StringFromBool(bool value); +[[nodiscard]] std::string StringFromBool(bool value); -std::string TabsToSpaces(int tab_size, std::string in); +[[nodiscard]] std::string TabsToSpaces(int tab_size, std::string in); void SplitString(const std::string& str, char delim, std::vector& output); @@ -34,14 +34,15 @@ bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _ void BuildCompleteFilename(std::string& _CompleteFilename, const std::string& _Path, const std::string& _Filename); -std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest); +[[nodiscard]] std::string ReplaceAll(std::string result, const std::string& src, + const std::string& dest); -std::string UTF16ToUTF8(const std::u16string& input); -std::u16string UTF8ToUTF16(const std::string& input); +[[nodiscard]] std::string UTF16ToUTF8(const std::u16string& input); +[[nodiscard]] std::u16string UTF8ToUTF16(const std::string& input); #ifdef _WIN32 -std::string UTF16ToUTF8(const std::wstring& input); -std::wstring UTF8ToUTF16W(const std::string& str); +[[nodiscard]] std::string UTF16ToUTF8(const std::wstring& input); +[[nodiscard]] std::wstring UTF8ToUTF16W(const std::string& str); #endif @@ -50,7 +51,7 @@ std::wstring UTF8ToUTF16W(const std::string& str); * `other` for equality. */ template -bool ComparePartialString(InIt begin, InIt end, const char* other) { +[[nodiscard]] bool ComparePartialString(InIt begin, InIt end, const char* other) { for (; begin != end && *other != '\0'; ++begin, ++other) { if (*begin != *other) { return false; @@ -78,6 +79,7 @@ std::string UTF16BufferToUTF8(const T& text) { * Creates a std::string from a fixed-size NUL-terminated char buffer. If the buffer isn't * NUL-terminated then the string ends at max_len characters. */ -std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, std::size_t max_len); +[[nodiscard]] std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, + std::size_t max_len); } // namespace Common diff --git a/src/common/telemetry.h b/src/common/telemetry.h index 56dc54007..3bf18cfda 100644 --- a/src/common/telemetry.h +++ b/src/common/telemetry.h @@ -63,30 +63,30 @@ public: void Accept(VisitorInterface& visitor) const override; - const std::string& GetName() const override { + [[nodiscard]] const std::string& GetName() const override { return name; } /** * Returns the type of the field. */ - FieldType GetType() const { + [[nodiscard]] FieldType GetType() const { return type; } /** * Returns the value of the field. */ - const T& GetValue() const { + [[nodiscard]] const T& GetValue() const { return value; } - bool operator==(const Field& other) const { + [[nodiscard]] bool operator==(const Field& other) const { return (type == other.type) && (name == other.name) && (value == other.value); } - bool operator!=(const Field& other) const { - return !(*this == other); + [[nodiscard]] bool operator!=(const Field& other) const { + return !operator==(other); } private: diff --git a/src/common/thread_queue_list.h b/src/common/thread_queue_list.h index af40bf09b..5995d76f2 100644 --- a/src/common/thread_queue_list.h +++ b/src/common/thread_queue_list.h @@ -19,19 +19,19 @@ struct ThreadQueueList { // (dynamically resizable) circular buffers to remove their overhead when // inserting and popping. - typedef unsigned int Priority; + using Priority = unsigned int; // Number of priority levels. (Valid levels are [0..NUM_QUEUES).) - static const Priority NUM_QUEUES = N; + static constexpr Priority NUM_QUEUES = N; ThreadQueueList() { first = nullptr; } // Only for debugging, returns priority level. - Priority contains(const T& uid) { + [[nodiscard]] Priority contains(const T& uid) const { for (Priority i = 0; i < NUM_QUEUES; ++i) { - Queue& cur = queues[i]; + const Queue& cur = queues[i]; if (std::find(cur.data.cbegin(), cur.data.cend(), uid) != cur.data.cend()) { return i; } @@ -40,8 +40,8 @@ struct ThreadQueueList { return -1; } - T get_first() { - Queue* cur = first; + [[nodiscard]] T get_first() const { + const Queue* cur = first; while (cur != nullptr) { if (!cur->data.empty()) { return cur->data.front(); @@ -117,7 +117,7 @@ struct ThreadQueueList { first = nullptr; } - bool empty(Priority priority) const { + [[nodiscard]] bool empty(Priority priority) const { const Queue* cur = &queues[priority]; return cur->data.empty(); } diff --git a/src/common/threadsafe_queue.h b/src/common/threadsafe_queue.h index 594d14c15..5584229a6 100644 --- a/src/common/threadsafe_queue.h +++ b/src/common/threadsafe_queue.h @@ -25,15 +25,15 @@ public: delete read_ptr; } - std::size_t Size() const { + [[nodiscard]] std::size_t Size() const { return size.load(); } - bool Empty() const { + [[nodiscard]] bool Empty() const { return Size() == 0; } - T& Front() const { + [[nodiscard]] T& Front() const { return read_ptr->current; } @@ -130,15 +130,15 @@ private: template class MPSCQueue { public: - std::size_t Size() const { + [[nodiscard]] std::size_t Size() const { return spsc_queue.Size(); } - bool Empty() const { + [[nodiscard]] bool Empty() const { return spsc_queue.Empty(); } - T& Front() const { + [[nodiscard]] T& Front() const { return spsc_queue.Front(); } diff --git a/src/common/timer.h b/src/common/timer.h index 27b521baa..8894a143d 100644 --- a/src/common/timer.h +++ b/src/common/timer.h @@ -19,18 +19,18 @@ public: // The time difference is always returned in milliseconds, regardless of alternative internal // representation - std::chrono::milliseconds GetTimeDifference(); + [[nodiscard]] std::chrono::milliseconds GetTimeDifference(); void AddTimeDifference(); - static std::chrono::seconds GetTimeSinceJan1970(); - static std::chrono::seconds GetLocalTimeSinceJan1970(); - static double GetDoubleTime(); + [[nodiscard]] static std::chrono::seconds GetTimeSinceJan1970(); + [[nodiscard]] static std::chrono::seconds GetLocalTimeSinceJan1970(); + [[nodiscard]] static double GetDoubleTime(); - static std::string GetTimeFormatted(); - std::string GetTimeElapsedFormatted() const; - std::chrono::milliseconds GetTimeElapsed(); + [[nodiscard]] static std::string GetTimeFormatted(); + [[nodiscard]] std::string GetTimeElapsedFormatted() const; + [[nodiscard]] std::chrono::milliseconds GetTimeElapsed(); - static std::chrono::milliseconds GetTimeMs(); + [[nodiscard]] static std::chrono::milliseconds GetTimeMs(); private: std::chrono::milliseconds m_LastTime; diff --git a/src/common/vector_math.h b/src/common/vector_math.h index ba7bd1aa7..8c14cf410 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h @@ -64,15 +64,15 @@ public: constexpr Vec2(const T& x_, const T& y_) : x(x_), y(y_) {} template - constexpr Vec2 Cast() const { + [[nodiscard]] constexpr Vec2 Cast() const { return Vec2(static_cast(x), static_cast(y)); } - static constexpr Vec2 AssignToAll(const T& f) { + [[nodiscard]] static constexpr Vec2 AssignToAll(const T& f) { return Vec2{f, f}; } - constexpr Vec2 operator+(const Vec2& other) const { + [[nodiscard]] constexpr Vec2 operator+(const Vec2& other) const { return {x + other.x, y + other.y}; } constexpr Vec2& operator+=(const Vec2& other) { @@ -80,7 +80,7 @@ public: y += other.y; return *this; } - constexpr Vec2 operator-(const Vec2& other) const { + [[nodiscard]] constexpr Vec2 operator-(const Vec2& other) const { return {x - other.x, y - other.y}; } constexpr Vec2& operator-=(const Vec2& other) { @@ -90,15 +90,15 @@ public: } template - constexpr Vec2, U>> operator-() const { + [[nodiscard]] constexpr Vec2, U>> operator-() const { return {-x, -y}; } - constexpr Vec2 operator*(const Vec2& other) const { + [[nodiscard]] constexpr Vec2 operator*(const Vec2& other) const { return {x * other.x, y * other.y}; } template - constexpr Vec2 operator*(const V& f) const { + [[nodiscard]] constexpr Vec2 operator*(const V& f) const { return {x * f, y * f}; } @@ -109,7 +109,7 @@ public: } template - constexpr Vec2 operator/(const V& f) const { + [[nodiscard]] constexpr Vec2 operator/(const V& f) const { return {x / f, y / f}; } @@ -119,18 +119,18 @@ public: return *this; } - constexpr T Length2() const { + [[nodiscard]] constexpr T Length2() const { return x * x + y * y; } // Only implemented for T=float - float Length() const; - float Normalize(); // returns the previous length, which is often useful + [[nodiscard]] float Length() const; + [[nodiscard]] float Normalize(); // returns the previous length, which is often useful - constexpr T& operator[](std::size_t i) { + [[nodiscard]] constexpr T& operator[](std::size_t i) { return *((&x) + i); } - constexpr const T& operator[](std::size_t i) const { + [[nodiscard]] constexpr const T& operator[](std::size_t i) const { return *((&x) + i); } @@ -140,46 +140,46 @@ public: } // Common aliases: UV (texel coordinates), ST (texture coordinates) - constexpr T& u() { + [[nodiscard]] constexpr T& u() { return x; } - constexpr T& v() { + [[nodiscard]] constexpr T& v() { return y; } - constexpr T& s() { + [[nodiscard]] constexpr T& s() { return x; } - constexpr T& t() { + [[nodiscard]] constexpr T& t() { return y; } - constexpr const T& u() const { + [[nodiscard]] constexpr const T& u() const { return x; } - constexpr const T& v() const { + [[nodiscard]] constexpr const T& v() const { return y; } - constexpr const T& s() const { + [[nodiscard]] constexpr const T& s() const { return x; } - constexpr const T& t() const { + [[nodiscard]] constexpr const T& t() const { return y; } // swizzlers - create a subvector of specific components - constexpr Vec2 yx() const { + [[nodiscard]] constexpr Vec2 yx() const { return Vec2(y, x); } - constexpr Vec2 vu() const { + [[nodiscard]] constexpr Vec2 vu() const { return Vec2(y, x); } - constexpr Vec2 ts() const { + [[nodiscard]] constexpr Vec2 ts() const { return Vec2(y, x); } }; template -constexpr Vec2 operator*(const V& f, const Vec2& vec) { +[[nodiscard]] constexpr Vec2 operator*(const V& f, const Vec2& vec) { return Vec2(f * vec.x, f * vec.y); } @@ -220,15 +220,15 @@ public: constexpr Vec3(const T& x_, const T& y_, const T& z_) : x(x_), y(y_), z(z_) {} template - constexpr Vec3 Cast() const { + [[nodiscard]] constexpr Vec3 Cast() const { return Vec3(static_cast(x), static_cast(y), static_cast(z)); } - static constexpr Vec3 AssignToAll(const T& f) { + [[nodiscard]] static constexpr Vec3 AssignToAll(const T& f) { return Vec3(f, f, f); } - constexpr Vec3 operator+(const Vec3& other) const { + [[nodiscard]] constexpr Vec3 operator+(const Vec3& other) const { return {x + other.x, y + other.y, z + other.z}; } @@ -239,7 +239,7 @@ public: return *this; } - constexpr Vec3 operator-(const Vec3& other) const { + [[nodiscard]] constexpr Vec3 operator-(const Vec3& other) const { return {x - other.x, y - other.y, z - other.z}; } @@ -251,16 +251,16 @@ public: } template - constexpr Vec3, U>> operator-() const { + [[nodiscard]] constexpr Vec3, U>> operator-() const { return {-x, -y, -z}; } - constexpr Vec3 operator*(const Vec3& other) const { + [[nodiscard]] constexpr Vec3 operator*(const Vec3& other) const { return {x * other.x, y * other.y, z * other.z}; } template - constexpr Vec3 operator*(const V& f) const { + [[nodiscard]] constexpr Vec3 operator*(const V& f) const { return {x * f, y * f, z * f}; } @@ -270,7 +270,7 @@ public: return *this; } template - constexpr Vec3 operator/(const V& f) const { + [[nodiscard]] constexpr Vec3 operator/(const V& f) const { return {x / f, y / f, z / f}; } @@ -280,20 +280,20 @@ public: return *this; } - constexpr T Length2() const { + [[nodiscard]] constexpr T Length2() const { return x * x + y * y + z * z; } // Only implemented for T=float - float Length() const; - Vec3 Normalized() const; - float Normalize(); // returns the previous length, which is often useful + [[nodiscard]] float Length() const; + [[nodiscard]] Vec3 Normalized() const; + [[nodiscard]] float Normalize(); // returns the previous length, which is often useful - constexpr T& operator[](std::size_t i) { + [[nodiscard]] constexpr T& operator[](std::size_t i) { return *((&x) + i); } - constexpr const T& operator[](std::size_t i) const { + [[nodiscard]] constexpr const T& operator[](std::size_t i) const { return *((&x) + i); } @@ -304,63 +304,63 @@ public: } // Common aliases: UVW (texel coordinates), RGB (colors), STQ (texture coordinates) - constexpr T& u() { + [[nodiscard]] constexpr T& u() { return x; } - constexpr T& v() { + [[nodiscard]] constexpr T& v() { return y; } - constexpr T& w() { + [[nodiscard]] constexpr T& w() { return z; } - constexpr T& r() { + [[nodiscard]] constexpr T& r() { return x; } - constexpr T& g() { + [[nodiscard]] constexpr T& g() { return y; } - constexpr T& b() { + [[nodiscard]] constexpr T& b() { return z; } - constexpr T& s() { + [[nodiscard]] constexpr T& s() { return x; } - constexpr T& t() { + [[nodiscard]] constexpr T& t() { return y; } - constexpr T& q() { + [[nodiscard]] constexpr T& q() { return z; } - constexpr const T& u() const { + [[nodiscard]] constexpr const T& u() const { return x; } - constexpr const T& v() const { + [[nodiscard]] constexpr const T& v() const { return y; } - constexpr const T& w() const { + [[nodiscard]] constexpr const T& w() const { return z; } - constexpr const T& r() const { + [[nodiscard]] constexpr const T& r() const { return x; } - constexpr const T& g() const { + [[nodiscard]] constexpr const T& g() const { return y; } - constexpr const T& b() const { + [[nodiscard]] constexpr const T& b() const { return z; } - constexpr const T& s() const { + [[nodiscard]] constexpr const T& s() const { return x; } - constexpr const T& t() const { + [[nodiscard]] constexpr const T& t() const { return y; } - constexpr const T& q() const { + [[nodiscard]] constexpr const T& q() const { return z; } @@ -369,7 +369,7 @@ public: // _DEFINE_SWIZZLER2 defines a single such function, DEFINE_SWIZZLER2 defines all of them for all // component names (x<->r) and permutations (xy<->yx) #define _DEFINE_SWIZZLER2(a, b, name) \ - constexpr Vec2 name() const { \ + [[nodiscard]] constexpr Vec2 name() const { \ return Vec2(a, b); \ } #define DEFINE_SWIZZLER2(a, b, a2, b2, a3, b3, a4, b4) \ @@ -390,7 +390,7 @@ public: }; template -constexpr Vec3 operator*(const V& f, const Vec3& vec) { +[[nodiscard]] constexpr Vec3 operator*(const V& f, const Vec3& vec) { return Vec3(f * vec.x, f * vec.y, f * vec.z); } @@ -439,16 +439,16 @@ public: : x(x_), y(y_), z(z_), w(w_) {} template - constexpr Vec4 Cast() const { + [[nodiscard]] constexpr Vec4 Cast() const { return Vec4(static_cast(x), static_cast(y), static_cast(z), static_cast(w)); } - static constexpr Vec4 AssignToAll(const T& f) { + [[nodiscard]] static constexpr Vec4 AssignToAll(const T& f) { return Vec4(f, f, f, f); } - constexpr Vec4 operator+(const Vec4& other) const { + [[nodiscard]] constexpr Vec4 operator+(const Vec4& other) const { return {x + other.x, y + other.y, z + other.z, w + other.w}; } @@ -460,7 +460,7 @@ public: return *this; } - constexpr Vec4 operator-(const Vec4& other) const { + [[nodiscard]] constexpr Vec4 operator-(const Vec4& other) const { return {x - other.x, y - other.y, z - other.z, w - other.w}; } @@ -473,16 +473,16 @@ public: } template - constexpr Vec4, U>> operator-() const { + [[nodiscard]] constexpr Vec4, U>> operator-() const { return {-x, -y, -z, -w}; } - constexpr Vec4 operator*(const Vec4& other) const { + [[nodiscard]] constexpr Vec4 operator*(const Vec4& other) const { return {x * other.x, y * other.y, z * other.z, w * other.w}; } template - constexpr Vec4 operator*(const V& f) const { + [[nodiscard]] constexpr Vec4 operator*(const V& f) const { return {x * f, y * f, z * f, w * f}; } @@ -493,7 +493,7 @@ public: } template - constexpr Vec4 operator/(const V& f) const { + [[nodiscard]] constexpr Vec4 operator/(const V& f) const { return {x / f, y / f, z / f, w / f}; } @@ -503,15 +503,15 @@ public: return *this; } - constexpr T Length2() const { + [[nodiscard]] constexpr T Length2() const { return x * x + y * y + z * z + w * w; } - constexpr T& operator[](std::size_t i) { + [[nodiscard]] constexpr T& operator[](std::size_t i) { return *((&x) + i); } - constexpr const T& operator[](std::size_t i) const { + [[nodiscard]] constexpr const T& operator[](std::size_t i) const { return *((&x) + i); } @@ -523,29 +523,29 @@ public: } // Common alias: RGBA (colors) - constexpr T& r() { + [[nodiscard]] constexpr T& r() { return x; } - constexpr T& g() { + [[nodiscard]] constexpr T& g() { return y; } - constexpr T& b() { + [[nodiscard]] constexpr T& b() { return z; } - constexpr T& a() { + [[nodiscard]] constexpr T& a() { return w; } - constexpr const T& r() const { + [[nodiscard]] constexpr const T& r() const { return x; } - constexpr const T& g() const { + [[nodiscard]] constexpr const T& g() const { return y; } - constexpr const T& b() const { + [[nodiscard]] constexpr const T& b() const { return z; } - constexpr const T& a() const { + [[nodiscard]] constexpr const T& a() const { return w; } @@ -557,7 +557,7 @@ public: // DEFINE_SWIZZLER2_COMP2 defines two component functions for all component names (x<->r) and // permutations (xy<->yx) #define _DEFINE_SWIZZLER2(a, b, name) \ - constexpr Vec2 name() const { \ + [[nodiscard]] constexpr Vec2 name() const { \ return Vec2(a, b); \ } #define DEFINE_SWIZZLER2_COMP1(a, a2) \ @@ -584,7 +584,7 @@ public: #undef _DEFINE_SWIZZLER2 #define _DEFINE_SWIZZLER3(a, b, c, name) \ - constexpr Vec3 name() const { \ + [[nodiscard]] constexpr Vec3 name() const { \ return Vec3(a, b, c); \ } #define DEFINE_SWIZZLER3_COMP1(a, a2) \ @@ -618,7 +618,7 @@ public: }; template -constexpr Vec4 operator*(const V& f, const Vec4& vec) { +[[nodiscard]] constexpr Vec4 operator*(const V& f, const Vec4& vec) { return {f * vec.x, f * vec.y, f * vec.z, f * vec.w}; } @@ -630,39 +630,41 @@ constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec2& a, const Vec2& b } template -constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec3& a, const Vec3& b) { +[[nodiscard]] constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec3& a, const Vec3& b) { return a.x * b.x + a.y * b.y + a.z * b.z; } template -constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec4& a, const Vec4& b) { +[[nodiscard]] constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec4& a, const Vec4& b) { return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; } template -constexpr Vec3 Cross(const Vec3& a, const Vec3& b) { +[[nodiscard]] constexpr Vec3 Cross(const Vec3& a, + const Vec3& b) { return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x}; } // linear interpolation via float: 0.0=begin, 1.0=end template -constexpr decltype(X{} * float{} + X{} * float{}) Lerp(const X& begin, const X& end, - const float t) { +[[nodiscard]] constexpr decltype(X{} * float{} + X{} * float{}) Lerp(const X& begin, const X& end, + const float t) { return begin * (1.f - t) + end * t; } // linear interpolation via int: 0=begin, base=end template -constexpr decltype((X{} * int{} + X{} * int{}) / base) LerpInt(const X& begin, const X& end, - const int t) { +[[nodiscard]] constexpr decltype((X{} * int{} + X{} * int{}) / base) LerpInt(const X& begin, + const X& end, + const int t) { return (begin * (base - t) + end * t) / base; } // bilinear interpolation. s is for interpolating x00-x01 and x10-x11, and t is for the second // interpolation. template -constexpr auto BilinearInterp(const X& x00, const X& x01, const X& x10, const X& x11, const float s, - const float t) { +[[nodiscard]] constexpr auto BilinearInterp(const X& x00, const X& x01, const X& x10, const X& x11, + const float s, const float t) { auto y0 = Lerp(x00, x01, s); auto y1 = Lerp(x10, x11, s); return Lerp(y0, y1, t); @@ -670,42 +672,42 @@ constexpr auto BilinearInterp(const X& x00, const X& x01, const X& x10, const X& // Utility vector factories template -constexpr Vec2 MakeVec(const T& x, const T& y) { +[[nodiscard]] constexpr Vec2 MakeVec(const T& x, const T& y) { return Vec2{x, y}; } template -constexpr Vec3 MakeVec(const T& x, const T& y, const T& z) { +[[nodiscard]] constexpr Vec3 MakeVec(const T& x, const T& y, const T& z) { return Vec3{x, y, z}; } template -constexpr Vec4 MakeVec(const T& x, const T& y, const Vec2& zw) { +[[nodiscard]] constexpr Vec4 MakeVec(const T& x, const T& y, const Vec2& zw) { return MakeVec(x, y, zw[0], zw[1]); } template -constexpr Vec3 MakeVec(const Vec2& xy, const T& z) { +[[nodiscard]] constexpr Vec3 MakeVec(const Vec2& xy, const T& z) { return MakeVec(xy[0], xy[1], z); } template -constexpr Vec3 MakeVec(const T& x, const Vec2& yz) { +[[nodiscard]] constexpr Vec3 MakeVec(const T& x, const Vec2& yz) { return MakeVec(x, yz[0], yz[1]); } template -constexpr Vec4 MakeVec(const T& x, const T& y, const T& z, const T& w) { +[[nodiscard]] constexpr Vec4 MakeVec(const T& x, const T& y, const T& z, const T& w) { return Vec4{x, y, z, w}; } template -constexpr Vec4 MakeVec(const Vec2& xy, const T& z, const T& w) { +[[nodiscard]] constexpr Vec4 MakeVec(const Vec2& xy, const T& z, const T& w) { return MakeVec(xy[0], xy[1], z, w); } template -constexpr Vec4 MakeVec(const T& x, const Vec2& yz, const T& w) { +[[nodiscard]] constexpr Vec4 MakeVec(const T& x, const Vec2& yz, const T& w) { return MakeVec(x, yz[0], yz[1], w); } @@ -713,17 +715,17 @@ constexpr Vec4 MakeVec(const T& x, const Vec2& yz, const T& w) { // Even if someone wanted to use an odd object like Vec2>, the compiler would error // out soon enough due to misuse of the returned structure. template -constexpr Vec4 MakeVec(const Vec2& xy, const Vec2& zw) { +[[nodiscard]] constexpr Vec4 MakeVec(const Vec2& xy, const Vec2& zw) { return MakeVec(xy[0], xy[1], zw[0], zw[1]); } template -constexpr Vec4 MakeVec(const Vec3& xyz, const T& w) { +[[nodiscard]] constexpr Vec4 MakeVec(const Vec3& xyz, const T& w) { return MakeVec(xyz[0], xyz[1], xyz[2], w); } template -constexpr Vec4 MakeVec(const T& x, const Vec3& yzw) { +[[nodiscard]] constexpr Vec4 MakeVec(const T& x, const Vec3& yzw) { return MakeVec(x, yzw[0], yzw[1], yzw[2]); } diff --git a/src/common/zstd_compression.h b/src/common/zstd_compression.h index 1715bae7a..3bef0072f 100644 --- a/src/common/zstd_compression.h +++ b/src/common/zstd_compression.h @@ -19,7 +19,8 @@ namespace Common::Compression { * * @return the compressed data. */ -std::vector CompressDataZSTD(const u8* source, std::size_t source_size, s32 compression_level); +[[nodiscard]] std::vector CompressDataZSTD(const u8* source, std::size_t source_size, + s32 compression_level); /** * Compresses a source memory region with Zstandard with the default compression level and returns @@ -30,7 +31,7 @@ std::vector CompressDataZSTD(const u8* source, std::size_t source_size, s32 * * @return the compressed data. */ -std::vector CompressDataZSTDDefault(const u8* source, std::size_t source_size); +[[nodiscard]] std::vector CompressDataZSTDDefault(const u8* source, std::size_t source_size); /** * Decompresses a source memory region with Zstandard and returns the uncompressed data in a vector. @@ -39,6 +40,6 @@ std::vector CompressDataZSTDDefault(const u8* source, std::size_t source_siz * * @return the decompressed data. */ -std::vector DecompressDataZSTD(const std::vector& compressed); +[[nodiscard]] std::vector DecompressDataZSTD(const std::vector& compressed); } // namespace Common::Compression diff --git a/src/core/hle/service/cecd/cecd.cpp b/src/core/hle/service/cecd/cecd.cpp index 55146c9bf..74fb0a111 100644 --- a/src/core/hle/service/cecd/cecd.cpp +++ b/src/core/hle/service/cecd/cecd.cpp @@ -1361,7 +1361,8 @@ void Module::CheckAndUpdateFile(const CecDataPathType path_type, const u32 ncch_ case CecDataPathType::MboxData: case CecDataPathType::MboxIcon: case CecDataPathType::MboxTitle: - default: {} + default: { + } } } diff --git a/src/core/movie.h b/src/core/movie.h index eff148090..e578b909c 100644 --- a/src/core/movie.h +++ b/src/core/movie.h @@ -42,8 +42,8 @@ public: return s_instance; } - void StartPlayback(const std::string& movie_file, - std::function completion_callback = [] {}); + void StartPlayback( + const std::string& movie_file, std::function completion_callback = [] {}); void StartRecording(const std::string& movie_file); /// Prepare to override the clock before playing back movies diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index 287a064c6..0c2f82fcb 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp @@ -226,8 +226,7 @@ void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 clie } else { failure_callback(); } - }) - .detach(); + }).detach(); } CalibrationConfigurationJob::CalibrationConfigurationJob( @@ -281,8 +280,7 @@ CalibrationConfigurationJob::CalibrationConfigurationJob( complete_event.Wait(); socket.Stop(); worker_thread.join(); - }) - .detach(); + }).detach(); } CalibrationConfigurationJob::~CalibrationConfigurationJob() { diff --git a/src/tests/core/arm/arm_test_common.cpp b/src/tests/core/arm/arm_test_common.cpp index 1bba53c7e..7d3827d03 100644 --- a/src/tests/core/arm/arm_test_common.cpp +++ b/src/tests/core/arm/arm_test_common.cpp @@ -17,7 +17,8 @@ TestEnvironment::TestEnvironment(bool mutable_memory_) timing = std::make_unique(1, 100); memory = std::make_unique(); - kernel = std::make_unique(*memory, *timing, [] {}, 0, 1, 0); + kernel = std::make_unique( + *memory, *timing, [] {}, 0, 1, 0); kernel->SetCurrentProcess(kernel->CreateProcess(kernel->CreateCodeSet("", 0))); page_table = kernel->GetCurrentProcess()->vm_manager.page_table; diff --git a/src/tests/core/hle/kernel/hle_ipc.cpp b/src/tests/core/hle/kernel/hle_ipc.cpp index f5623c8c1..890343cd8 100644 --- a/src/tests/core/hle/kernel/hle_ipc.cpp +++ b/src/tests/core/hle/kernel/hle_ipc.cpp @@ -24,7 +24,8 @@ static std::shared_ptr MakeObject(Kernel::KernelSystem& kernel) { TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel]") { Core::Timing timing(1, 100); Memory::MemorySystem memory; - Kernel::KernelSystem kernel(memory, timing, [] {}, 0, 1, 0); + Kernel::KernelSystem kernel( + memory, timing, [] {}, 0, 1, 0); auto [server, client] = kernel.CreateSessionPair(); HLERequestContext context(kernel, std::move(server), nullptr); @@ -239,7 +240,8 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") { Core::Timing timing(1, 100); Memory::MemorySystem memory; - Kernel::KernelSystem kernel(memory, timing, [] {}, 0, 1, 0); + Kernel::KernelSystem kernel( + memory, timing, [] {}, 0, 1, 0); auto [server, client] = kernel.CreateSessionPair(); HLERequestContext context(kernel, std::move(server), nullptr); diff --git a/src/tests/core/memory/memory.cpp b/src/tests/core/memory/memory.cpp index 6a499ed62..ebd4e1c2f 100644 --- a/src/tests/core/memory/memory.cpp +++ b/src/tests/core/memory/memory.cpp @@ -13,7 +13,8 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") { Core::Timing timing(1, 100); Memory::MemorySystem memory; - Kernel::KernelSystem kernel(memory, timing, [] {}, 0, 1, 0); + Kernel::KernelSystem kernel( + memory, timing, [] {}, 0, 1, 0); SECTION("these regions should not be mapped on an empty process") { auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0)); CHECK(Memory::IsValidVirtualAddress(*process, Memory::PROCESS_IMAGE_VADDR) == false);