diff --git a/src/Enum.hpp b/src/Enum.hpp index 6226bcf..a76fe16 100644 --- a/src/Enum.hpp +++ b/src/Enum.hpp @@ -52,7 +52,7 @@ #define ENUM_WITH_START_VALUE(name, type, startValue, ...) \ enum class name : type { \ - MACRO_UTILS_FOR_EACH_WITH_VALUE(ENUM_VALUE, startValue + ___MACRO_UTILS_NARGS(__VA_ARGS__) - 1, __VA_ARGS__) \ + MACRO_UTILS_FOR_EACH_WITH_VALUE(ENUM_VALUE, startValue + ___MACRO_UTILS_NARGS(__VA_ARGS__) - 1, __VA_ARGS__) \ }; \ class name##Helper { \ ALLOW_UINTEGER_OVERFLOW \ diff --git a/src/Memory/__OptionalUniquePtr.hpp b/src/Memory/__OptionalUniquePtr.hpp index 70044a3..19bae5d 100644 --- a/src/Memory/__OptionalUniquePtr.hpp +++ b/src/Memory/__OptionalUniquePtr.hpp @@ -19,11 +19,12 @@ namespace ArbUt { /// @brief Initialise a OptionalUniquePtr with a specific raw pointer. inline OptionalUniquePtr(T* nullable ptr) : _raw(ptr){}; + /// @brief We do not allow copying or moving of unique pointers, as that would cause memory leaks and use after + /// frees. NO_COPY_OR_MOVE(OptionalUniquePtr); ~OptionalUniquePtr() noexcept { delete _raw; } - /// @brief Return whether the pointer is null or not. [[nodiscard]] inline bool HasValue() const noexcept { return _raw != nullptr; } diff --git a/src/Memory/__ScopedPtr.hpp b/src/Memory/__ScopedPtr.hpp index 7bfc88b..e13c66f 100644 --- a/src/Memory/__ScopedPtr.hpp +++ b/src/Memory/__ScopedPtr.hpp @@ -48,11 +48,12 @@ namespace ArbUt { /// @brief Operator for access into underlying pointer. inline T* non_null operator->() const noexcept { return _raw; } - /// @brief Get the raw underlying pointer, and take ownership of it. This removes the existing pointer in here. - #if defined(__clang__) - [[clang::no_sanitize("nullability-assign")]] - #endif - inline T* non_null TakeOwnership() noexcept { +/// @brief Get the raw underlying pointer, and take ownership of it. This removes the existing pointer in here. +#if defined(__clang__) + [[clang::no_sanitize("nullability-assign")]] +#endif + inline T* non_null + TakeOwnership() noexcept { auto raw = _raw; _raw = nullptr; return raw; diff --git a/src/Memory/__UniquePtr.hpp b/src/Memory/__UniquePtr.hpp index ba2f943..a8f3204 100644 --- a/src/Memory/__UniquePtr.hpp +++ b/src/Memory/__UniquePtr.hpp @@ -17,12 +17,14 @@ namespace ArbUt { public: inline UniquePtr() {} /// @brief Initialise a UniquePtr with a specific raw pointer. - inline UniquePtr(T* non_null ptr) : _raw(ptr) { EnsureNotNull(ptr) }; + inline UniquePtr(T* non_null ptr) : _raw(ptr){EnsureNotNull(ptr)}; + /// @brief We do not allow copying or moving of unique pointers, as that would cause memory leaks and use after + /// frees. NO_COPY_OR_MOVE(UniquePtr); #if !WINDOWS // This doesn't work on mingw-w64 for some reason - /// @brief Do not allow nullreference assignment + /// @brief Do not allow nullreference assignment UniquePtr(std::nullptr_t) = delete; #endif diff --git a/src/Misc.hpp b/src/Misc.hpp index 2305789..be32451 100644 --- a/src/Misc.hpp +++ b/src/Misc.hpp @@ -9,6 +9,6 @@ /* @brief: Copy assignment is not allowed */ \ type& operator=(const type&) = delete; \ /* @brief: Copy assignment is not allowed */ \ - type& operator=(type&&) = delete; + type& operator=(type&&) = delete #endif // ARBUTILS_MISC_HPP diff --git a/src/Random.hpp b/src/Random.hpp index f414157..f712d0c 100644 --- a/src/Random.hpp +++ b/src/Random.hpp @@ -3,8 +3,8 @@ // PCG uses unsigned shifts, and overflows a lot. Disable the sanitizer for that. #if defined(__clang__) -// If we don't ignore this diagnostic, and the sanitizer is not known yet in the clang version, this spams tens of thousands -// of warnings. Hence we disable it for a bit. +// If we don't ignore this diagnostic, and the sanitizer is not known yet in the clang version, this spams tens of +// thousands of warnings. Hence we disable it for a bit. #pragma GCC diagnostic push #pragma clang diagnostic ignored "-Wunknown-sanitizers" #pragma clang attribute push(__attribute__((no_sanitize("unsigned-shift-base", "unsigned-integer-overflow"))), \ diff --git a/src/String/StringView.hpp b/src/String/StringView.hpp index c5d6b3a..4f71930 100644 --- a/src/String/StringView.hpp +++ b/src/String/StringView.hpp @@ -24,12 +24,12 @@ namespace ArbUt { EnsureNotNull(value); // For GCC we need to disable a diagnostic that does not like this. #if defined(__GNUC__) && !defined(__clang__) - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wstringop-truncation" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-truncation" #endif strncpy(_value, value, length); #if defined(__GNUC__) && !defined(__clang__) - #pragma GCC diagnostic pop +#pragma GCC diagnostic pop #endif _value[length] = 0; @@ -94,7 +94,8 @@ namespace ArbUt { /// @brief Instantiate a StringView using a C string. /// @param str A null-terminated C string. StringView(const char* non_null str) - : BasicStringView(CalcLength(str), Hash(str, CalcLength(str))), _str(new __ConstStringCharHolder(str, CalcLength(str))) {} + : BasicStringView(CalcLength(str), Hash(str, CalcLength(str))), + _str(new __ConstStringCharHolder(str, CalcLength(str))) {} /// @brief Instantiate a StringView using a C string, as well as it's length. /// @param str A null-terminated C string. /// @param length The length of the C string @@ -143,9 +144,13 @@ namespace ArbUt { return _hash != Hash(rhs.data(), rhs.size()); } /// @brief Check equality with standard C style string. - inline constexpr bool operator==(const char* non_null rhs) const noexcept final { return _hash == Hash(rhs, CalcLength(rhs)); } + inline constexpr bool operator==(const char* non_null rhs) const noexcept final { + return _hash == Hash(rhs, CalcLength(rhs)); + } /// @brief Check inequality with standard C style string. - inline constexpr bool operator!=(const char* non_null rhs) const noexcept final { return _hash != Hash(rhs, CalcLength(rhs)); } + inline constexpr bool operator!=(const char* non_null rhs) const noexcept final { + return _hash != Hash(rhs, CalcLength(rhs)); + } /// @brief Calculates the hash for a given C string. /// @param val A null-terminated C string. diff --git a/src/String/StringViewLiteral.hpp b/src/String/StringViewLiteral.hpp index 05bffaf..8ee5416 100644 --- a/src/String/StringViewLiteral.hpp +++ b/src/String/StringViewLiteral.hpp @@ -41,9 +41,13 @@ namespace ArbUt { return _hash != Hash(rhs.data(), rhs.size()); } /// @brief Check equality with standard C style string. - inline constexpr bool operator==(const char* non_null rhs) const noexcept final { return _hash == Hash(rhs, CalcLength(rhs)); } + inline constexpr bool operator==(const char* non_null rhs) const noexcept final { + return _hash == Hash(rhs, CalcLength(rhs)); + } /// @brief Check inequality with standard C style string. - inline constexpr bool operator!=(const char* non_null rhs) const noexcept final { return _hash != Hash(rhs, CalcLength(rhs)); } + inline constexpr bool operator!=(const char* non_null rhs) const noexcept final { + return _hash != Hash(rhs, CalcLength(rhs)); + } }; }