From bb05d8c12a3498939b10b9bfe3a34fd0dcce0686 Mon Sep 17 00:00:00 2001 From: Tobias Date: Wed, 9 Nov 2022 23:14:28 +0100 Subject: [PATCH] src/CMakeLists: Enforce multiple warnings on MSVC (#5692) --- externals/microprofile/microprofile.h | 38 ++++++++++--------- src/CMakeLists.txt | 18 +++++++++ src/citra/citra.cpp | 3 +- src/common/vector_math.h | 4 +- src/core/cheats/cheats.cpp | 4 +- src/core/cheats/cheats.h | 4 +- src/core/gdbstub/gdbstub.cpp | 2 +- src/core/hle/service/ir/extra_hid.cpp | 2 +- .../renderer_opengl/gl_shader_manager.cpp | 5 ++- .../shader/shader_jit_x64_compiler.cpp | 3 +- 10 files changed, 53 insertions(+), 30 deletions(-) diff --git a/externals/microprofile/microprofile.h b/externals/microprofile/microprofile.h index 2b8017c6a..3db1e15f7 100644 --- a/externals/microprofile/microprofile.h +++ b/externals/microprofile/microprofile.h @@ -834,7 +834,7 @@ struct MicroProfile inline int MicroProfileLogType(MicroProfileLogEntry Index) { - return ((MP_LOG_BEGIN_MASK & Index)>>62) & 0x3; + return (int)(((MP_LOG_BEGIN_MASK & Index)>>62) & 0x3ULL); } inline uint64_t MicroProfileLogTimerIndex(MicroProfileLogEntry Index) @@ -881,12 +881,12 @@ T MicroProfileMax(T a, T b) inline int64_t MicroProfileMsToTick(float fMs, int64_t nTicksPerSecond) { - return (int64_t)(fMs*0.001f*nTicksPerSecond); + return (int64_t)(fMs*0.001f*(float)nTicksPerSecond); } inline float MicroProfileTickToMsMultiplier(int64_t nTicksPerSecond) { - return 1000.f / nTicksPerSecond; + return 1000.f / (float)nTicksPerSecond; } inline uint16_t MicroProfileGetGroupIndex(MicroProfileToken t) @@ -902,8 +902,10 @@ inline uint16_t MicroProfileGetGroupIndex(MicroProfileToken t) #include #define snprintf _snprintf +#ifdef _MSC_VER #pragma warning(push) #pragma warning(disable: 4244) +#endif int64_t MicroProfileTicksPerSecondCpu() { static int64_t nTicksPerSecond = 0; @@ -929,14 +931,14 @@ typedef void* (*MicroProfileThreadFunc)(void*); #ifndef _WIN32 typedef pthread_t MicroProfileThread; -void MicroProfileThreadStart(MicroProfileThread* pThread, MicroProfileThreadFunc Func) +inline void MicroProfileThreadStart(MicroProfileThread* pThread, MicroProfileThreadFunc Func) { pthread_attr_t Attr; int r = pthread_attr_init(&Attr); MP_ASSERT(r == 0); pthread_create(pThread, &Attr, Func, 0); } -void MicroProfileThreadJoin(MicroProfileThread* pThread) +inline void MicroProfileThreadJoin(MicroProfileThread* pThread) { int r = pthread_join(*pThread, 0); MP_ASSERT(r == 0); @@ -953,11 +955,11 @@ DWORD _stdcall ThreadTrampoline(void* pFunc) return static_cast(reinterpret_cast(F(0))); } -void MicroProfileThreadStart(MicroProfileThread* pThread, MicroProfileThreadFunc Func) +inline void MicroProfileThreadStart(MicroProfileThread* pThread, MicroProfileThreadFunc Func) { *pThread = CreateThread(0, 0, ThreadTrampoline, Func, 0, 0); } -void MicroProfileThreadJoin(MicroProfileThread* pThread) +inline void MicroProfileThreadJoin(MicroProfileThread* pThread) { WaitForSingleObject(*pThread, INFINITE); CloseHandle(*pThread); @@ -1154,7 +1156,7 @@ inline void MicroProfileSetThreadLog(MicroProfileThreadLog* pLog) pthread_setspecific(g_MicroProfileThreadLogKey, pLog); } #else -MicroProfileThreadLog* MicroProfileGetThreadLog() +inline MicroProfileThreadLog* MicroProfileGetThreadLog() { return g_MicroProfileThreadLog; } @@ -1270,7 +1272,7 @@ MicroProfileToken MicroProfileFindToken(const char* pGroup, const char* pName) return MICROPROFILE_INVALID_TOKEN; } -uint16_t MicroProfileGetGroup(const char* pGroup, MicroProfileTokenType Type) +inline uint16_t MicroProfileGetGroup(const char* pGroup, MicroProfileTokenType Type) { for(uint32_t i = 0; i < S.nGroupCount; ++i) { @@ -1299,7 +1301,7 @@ uint16_t MicroProfileGetGroup(const char* pGroup, MicroProfileTokenType Type) return nGroupIndex; } -void MicroProfileRegisterGroup(const char* pGroup, const char* pCategory, uint32_t nColor) +inline void MicroProfileRegisterGroup(const char* pGroup, const char* pCategory, uint32_t nColor) { int nCategoryIndex = -1; for(uint32_t i = 0; i < S.nCategoryCount; ++i) @@ -1465,7 +1467,7 @@ void MicroProfileGpuLeave(MicroProfileToken nToken_, uint64_t nTickStart) } } -void MicroProfileContextSwitchPut(MicroProfileContextSwitch* pContextSwitch) +inline void MicroProfileContextSwitchPut(MicroProfileContextSwitch* pContextSwitch) { if(S.nRunning || pContextSwitch->nTicks <= S.nPauseTicks) { @@ -1746,10 +1748,10 @@ void MicroProfileFlip() } } } - for(uint32_t i = 0; i < MICROPROFILE_MAX_GROUPS; ++i) + for(uint32_t j = 0; j < MICROPROFILE_MAX_GROUPS; ++j) { - pLog->nGroupTicks[i] += nGroupTicks[i]; - pFrameGroup[i] += nGroupTicks[i]; + pLog->nGroupTicks[j] += nGroupTicks[j]; + pFrameGroup[j] += nGroupTicks[j]; } pLog->nStackPos = nStackPos; } @@ -1917,7 +1919,7 @@ void MicroProfileSetEnableAllGroups(bool bEnableAllGroups) S.nAllGroupsWanted = bEnableAllGroups ? 1 : 0; } -void MicroProfileEnableCategory(const char* pCategory, bool bEnabled) +inline void MicroProfileEnableCategory(const char* pCategory, bool bEnabled) { int nCategoryIndex = -1; for(uint32_t i = 0; i < S.nCategoryCount; ++i) @@ -2027,7 +2029,7 @@ void MicroProfileForceDisableGroup(const char* pGroup, MicroProfileTokenType Typ } -void MicroProfileCalcAllTimers(float* pTimers, float* pAverage, float* pMax, float* pCallAverage, float* pExclusive, float* pAverageExclusive, float* pMaxExclusive, float* pTotal, uint32_t nSize) +inline void MicroProfileCalcAllTimers(float* pTimers, float* pAverage, float* pMax, float* pCallAverage, float* pExclusive, float* pAverageExclusive, float* pMaxExclusive, float* pTotal, uint32_t nSize) { for(uint32_t i = 0; i < S.nTotalTimers && i < nSize; ++i) { @@ -3332,7 +3334,7 @@ bool MicroProfileIsLocalThread(uint32_t nThreadId) #endif #else -bool MicroProfileIsLocalThread(uint32_t nThreadId){return false;} +bool MicroProfileIsLocalThread([[maybe_unused]] uint32_t nThreadId) { return false; } void MicroProfileStopContextSwitchTrace(){} void MicroProfileStartContextSwitchTrace(){} @@ -3580,7 +3582,7 @@ int MicroProfileGetGpuTickReference(int64_t* pOutCpu, int64_t* pOutGpu) #undef S -#ifdef _WIN32 +#ifdef _MSC_VER #pragma warning(pop) #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e2d79f730..488f92fae 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -46,7 +46,16 @@ if (MSVC) # Warnings /W3 + /we4062 # enumerator 'identifier' in a switch of enum 'enumeration' is not handled + /we4101 # 'identifier': unreferenced local variable + /we4265 # 'class': class has virtual functions, but destructor is not virtual /we4267 # 'var': conversion from 'size_t' to 'type', possible loss of data + /we4388 # signed/unsigned mismatch + /we4547 # 'operator' : operator before comma has no effect; expected operator with side-effect + /we4549 # 'operator1': operator before comma has no effect; did you intend 'operator2'? + /we4555 # Expression has no effect; expected expression with side-effect + /we4834 # Discarding return value of function with 'nodiscard' attribute + /we5038 # data member 'member1' will be initialized after data member 'member2' ) else() add_compile_options( @@ -64,7 +73,16 @@ if (MSVC) # Warnings /W3 + /we4062 # enumerator 'identifier' in a switch of enum 'enumeration' is not handled + /we4101 # 'identifier': unreferenced local variable + /we4265 # 'class': class has virtual functions, but destructor is not virtual /we4267 # 'var': conversion from 'size_t' to 'type', possible loss of data + /we4388 # signed/unsigned mismatch + /we4547 # 'operator' : operator before comma has no effect; expected operator with side-effect + /we4549 # 'operator1': operator before comma has no effect; did you intend 'operator2'? + /we4555 # Expression has no effect; expected expression with side-effect + /we4834 # Discarding return value of function with 'nodiscard' attribute + /we5038 # data member 'member1' will be initialized after data member 'member2' ) endif() diff --git a/src/citra/citra.cpp b/src/citra/citra.cpp index 8b5ff3b05..7761d7680 100644 --- a/src/citra/citra.cpp +++ b/src/citra/citra.cpp @@ -139,7 +139,8 @@ static void OnNetworkError(const Network::RoomMember::Error& error) { LOG_ERROR(Network, "You have been banned by the host"); break; default: - LOG_ERROR(Network, "Unknown network error {}", error); + LOG_ERROR(Network, "Unknown network error: {}", error); + break; } } diff --git a/src/common/vector_math.h b/src/common/vector_math.h index 4ce3be8f5..7033ad8ac 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h @@ -138,7 +138,7 @@ public: // Only implemented for T=float [[nodiscard]] float Length() const; - [[nodiscard]] float Normalize(); // returns the previous length, which is often useful + float Normalize(); // returns the previous length, which is often useful [[nodiscard]] constexpr T& operator[](std::size_t i) { return *((&x) + i); @@ -314,7 +314,7 @@ public: // Only implemented for T=float [[nodiscard]] float Length() const; [[nodiscard]] Vec3 Normalized() const; - [[nodiscard]] float Normalize(); // returns the previous length, which is often useful + float Normalize(); // returns the previous length, which is often useful [[nodiscard]] constexpr T& operator[](std::size_t i) { return *((&x) + i); diff --git a/src/core/cheats/cheats.cpp b/src/core/cheats/cheats.cpp index 9d9e94121..89b5f034f 100644 --- a/src/core/cheats/cheats.cpp +++ b/src/core/cheats/cheats.cpp @@ -45,7 +45,7 @@ void CheatEngine::AddCheat(const std::shared_ptr& cheat) { cheats_list.push_back(cheat); } -void CheatEngine::RemoveCheat(int index) { +void CheatEngine::RemoveCheat(std::size_t index) { std::unique_lock lock(cheats_list_mutex); if (index < 0 || index >= static_cast(cheats_list.size())) { LOG_ERROR(Core_Cheats, "Invalid index {}", index); @@ -54,7 +54,7 @@ void CheatEngine::RemoveCheat(int index) { cheats_list.erase(cheats_list.begin() + index); } -void CheatEngine::UpdateCheat(int index, const std::shared_ptr& new_cheat) { +void CheatEngine::UpdateCheat(std::size_t index, const std::shared_ptr& new_cheat) { std::unique_lock lock(cheats_list_mutex); if (index < 0 || index >= static_cast(cheats_list.size())) { LOG_ERROR(Core_Cheats, "Invalid index {}", index); diff --git a/src/core/cheats/cheats.h b/src/core/cheats/cheats.h index 813263236..9d339abb7 100644 --- a/src/core/cheats/cheats.h +++ b/src/core/cheats/cheats.h @@ -29,8 +29,8 @@ public: void Connect(); std::vector> GetCheats() const; void AddCheat(const std::shared_ptr& cheat); - void RemoveCheat(int index); - void UpdateCheat(int index, const std::shared_ptr& new_cheat); + void RemoveCheat(std::size_t index); + void UpdateCheat(std::size_t index, const std::shared_ptr& new_cheat); void SaveCheatFile() const; private: diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index c7203771a..932d1f06d 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp @@ -705,7 +705,7 @@ static bool IsDataAvailable() { fd_set fd_socket; FD_ZERO(&fd_socket); - FD_SET(gdbserver_socket, &fd_socket); + FD_SET(static_cast(gdbserver_socket), &fd_socket); struct timeval t; t.tv_sec = 0; diff --git a/src/core/hle/service/ir/extra_hid.cpp b/src/core/hle/service/ir/extra_hid.cpp index 23701fd95..777615d7f 100644 --- a/src/core/hle/service/ir/extra_hid.cpp +++ b/src/core/hle/service/ir/extra_hid.cpp @@ -198,7 +198,7 @@ void ExtraHID::HandleReadCalibrationDataRequest(const std::vector& request_b const u16 offset = Common::AlignDown(request.offset, 16); const u16 size = Common::AlignDown(request.size, 16); - if (offset + size > calibration_data.size()) { + if (static_cast(offset + size) > calibration_data.size()) { LOG_ERROR(Service_IR, "Read beyond the end of calibration data! (offset={}, size={})", offset, size); return; diff --git a/src/video_core/renderer_opengl/gl_shader_manager.cpp b/src/video_core/renderer_opengl/gl_shader_manager.cpp index fa9398978..9b8033b41 100644 --- a/src/video_core/renderer_opengl/gl_shader_manager.cpp +++ b/src/video_core/renderer_opengl/gl_shader_manager.cpp @@ -93,8 +93,9 @@ static void SetShaderUniformBlockBinding(GLuint shader, const char* name, Unifor } GLint ub_size = 0; glGetActiveUniformBlockiv(shader, ub_index, GL_UNIFORM_BLOCK_DATA_SIZE, &ub_size); - ASSERT_MSG(ub_size == expected_size, "Uniform block size did not match! Got {}, expected {}", - static_cast(ub_size), expected_size); + ASSERT_MSG(static_cast(ub_size) == expected_size, + "Uniform block size did not match! Got {}, expected {}", static_cast(ub_size), + expected_size); glUniformBlockBinding(shader, ub_index, static_cast(binding)); } diff --git a/src/video_core/shader/shader_jit_x64_compiler.cpp b/src/video_core/shader/shader_jit_x64_compiler.cpp index b010aaa6f..bcf3d21ec 100644 --- a/src/video_core/shader/shader_jit_x64_compiler.cpp +++ b/src/video_core/shader/shader_jit_x64_compiler.cpp @@ -192,7 +192,8 @@ void JitShader::Compile_SwizzleSrc(Instruction instr, unsigned src_num, SourceRe } int src_offset_disp = (int)src_offset; - ASSERT_MSG(src_offset == src_offset_disp, "Source register offset too large for int type"); + ASSERT_MSG(src_offset == static_cast(src_offset_disp), + "Source register offset too large for int type"); unsigned operand_desc_id;