From 1549ef27a7f0c35d29a5312597273891b2de9d06 Mon Sep 17 00:00:00 2001 From: Patrick Wuttke Date: Sat, 5 Aug 2023 17:47:59 +0200 Subject: [PATCH] Fixed some more or less valid clang and clang-tidy errors. --- source/mijin/io/stream.cpp | 3 +++ source/mijin/util/scope_guard.hpp | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/source/mijin/io/stream.cpp b/source/mijin/io/stream.cpp index b7d04c5..5f48d5b 100644 --- a/source/mijin/io/stream.cpp +++ b/source/mijin/io/stream.cpp @@ -169,6 +169,9 @@ StreamError FileStream::seek(std::intptr_t pos, SeekMode seekMode) case SeekMode::RELATIVE_TO_END: origin = SEEK_END; break; + default: + assert(!"Invalid value passed as seekMode!"); + return StreamError::UNKNOWN_ERROR; } const int result = std::fseek(handle, static_cast(pos), origin); if (result != 0 || std::ferror(handle)) { diff --git a/source/mijin/util/scope_guard.hpp b/source/mijin/util/scope_guard.hpp index 8a54469..fd343b1 100644 --- a/source/mijin/util/scope_guard.hpp +++ b/source/mijin/util/scope_guard.hpp @@ -7,7 +7,7 @@ #include "./common_macros.hpp" #define MIJIN_SCOPE_EXIT_NAMED(name) \ -mijin::ScopeExitGuard name = [&]() +const mijin::ScopeExitGuard name = [&]() #define MIJIN_SCOPE_EXIT MIJIN_SCOPE_EXIT_NAMED(MIJIN_CONCAT(MIJIN_CONCAT(scope_guard_, __LINE__), __)) @@ -16,7 +16,7 @@ namespace mijin class ScopeExitGuard { private: - std::function func; + mutable std::function func; // variable is declared const to make clang-tidy happy, but we still want to be able to reset() public: template inline ScopeExitGuard(TFunc&& func_) noexcept : func(std::forward(func_)) {} @@ -32,7 +32,7 @@ public: ScopeExitGuard& operator=(const ScopeExitGuard&) noexcept = delete; ScopeExitGuard& operator=(ScopeExitGuard&&) noexcept = delete; - inline void reset() noexcept + inline void reset() const noexcept { func = {}; }