From 54acd7514dc0a2e9d593dd6312eae90ae6c0d6b5 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Wed, 16 Oct 2024 09:42:03 +0200 Subject: Fix/suppress MSVC /Wall warnings --- src/_pch.h | 28 ++++++++++++++++++++++++++++ src/intercopycontext.cpp | 6 +++--- src/keeper.cpp | 12 ++++++------ src/keeper.h | 4 ++-- src/lanes.cpp | 8 ++++---- src/state.cpp | 4 ++-- src/threading.cpp | 8 ++++---- src/uniquekey.h | 7 ++++++- src/universe.cpp | 2 +- 9 files changed, 56 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/_pch.h b/src/_pch.h index 21d862e..1c7b7dc 100644 --- a/src/_pch.h +++ b/src/_pch.h @@ -26,6 +26,14 @@ #include #include +#ifdef _MSC_VER + +// warning level /Wall triggers a bunch of warnings in Lua headers. we can't do anything about that, so suppress them +#pragma warning(push) +#pragma warning(disable : 4820) // 'n' bytes padding added after data member 'x' + +#endif // _MSC_VER + #ifdef __cplusplus extern "C" { @@ -36,3 +44,23 @@ extern "C" #ifdef __cplusplus } #endif // __cplusplus + +#ifdef _MSC_VER + +#pragma warning(pop) + +#pragma warning(disable : 4061) // enumerator 'x' in switch of 'y' is not explicitly handled by a case label +#pragma warning(disable : 4514) // 'x': unreferenced inline function has been removed +#pragma warning(disable : 4623) // 'x': default constructor was implicitly defined as deleted +#pragma warning(disable : 4623) // 'x': default constructor was implicitly defined as deleted +#pragma warning(disable : 4625) // 'x': copy constructor was implicitly defined as deleted +#pragma warning(disable : 4626) // 'x': assignment operator was implicitly defined as deleted +#pragma warning(disable : 4820) // 'n' bytes padding added after data member 'x' +#pragma warning(disable : 5026) // 'x': move constructor was implicitly defined as deleted +#pragma warning(disable : 5027) // 'x': move assignment operator was implicitly defined as deleted +#pragma warning(disable : 5039) // 'x': pointer or reference to potentially throwing function passed to 'extern "C"' function under -EHc. Undefined behavior may occur if this function throws an exception. +#pragma warning(disable : 5045) // Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified +#pragma warning(disable : 5220) // 'x': a non-static data member with a volatile qualified type no longer implies that compiler generated copy/move constructors and copy/move assignment operators are not trivial +#pragma warning(disable : 5246) // 'x': the initialization of a subobject should be wrapped in braces + +#endif // _MSC_VER diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index d21995c..473ebfd 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp @@ -864,13 +864,13 @@ LuaType InterCopyContext::processConversion() const _source = lua_touserdata(L1, -1); void* _clone{ nullptr }; // get the number of bytes to allocate for the clone - size_t const userdata_size{ lua_rawlen(L1, kIdxTop) }; + size_t const _userdata_size{ lua_rawlen(L1, kIdxTop) }; { // extract uservalues (don't transfer them yet) int const _nuv{ luaG_getalluservalues(L1, source_i) }; // L1: ... u [uv]* STACK_CHECK(L1, _nuv + 1); // create the clone userdata with the required number of uservalue slots - _clone = lua_newuserdatauv(L2, userdata_size, _nuv); // L2: ... mt u + _clone = lua_newuserdatauv(L2, _userdata_size, _nuv); // L2: ... mt u // add it in the cache lua_pushlightuserdata(L2, _source); // L2: ... mt u source lua_pushvalue(L2, -2); // L2: ... mt u source u @@ -906,7 +906,7 @@ LuaType InterCopyContext::processConversion() const lua_remove(L2, -2); // L2: ... u __lanesclone lua_pushlightuserdata(L2, _clone); // L2: ... u __lanesclone clone lua_pushlightuserdata(L2, _source); // L2: ... u __lanesclone clone source - lua_pushinteger(L2, userdata_size); // L2: ... u __lanesclone clone source size + lua_pushinteger(L2, static_cast(_userdata_size)); // L2: ... u __lanesclone clone source size // clone:__lanesclone(dest, source, size) lua_call(L2, 3, 0); // L2: ... u } else { // regular function diff --git a/src/keeper.cpp b/src/keeper.cpp index 46f580b..bea91a7 100644 --- a/src/keeper.cpp +++ b/src/keeper.cpp @@ -790,7 +790,7 @@ int Keeper::PushLindaStorage(Linda& linda_, DestState const L_) void Keepers::DeleteKV::operator()(Keeper* const k_) const { - for (Keeper& _k : std::views::counted(k_, count)) { + for (auto& _k : std::span(k_, count)) { _k.~Keeper(); } U->internalAllocator.free(k_, count * sizeof(Keeper)); @@ -826,7 +826,7 @@ void Keepers::close() // when keeper N+1 is closed, object is GCed, linda operation is called, which attempts to acquire keeper N, whose Lua state no longer exists // in that case, the linda operation should do nothing. which means that these operations must check for keeper acquisition success // which is early-outed with a keepers->nbKeepers null-check - size_t const _nbKeepers{ std::exchange(_kv.nbKeepers, 0) }; + size_t const _nbKeepers{ std::exchange(_kv.nbKeepers, size_t{ 0 }) }; for (size_t const _i : std::ranges::iota_view{ size_t{ 0 }, _nbKeepers }) { if (!_closeOneKeeper(_kv.keepers[_i])) { // detected partial init: destroy only the mutexes that got initialized properly @@ -889,7 +889,7 @@ void Keepers::close() * settings table is expected at position 1 on the stack */ -void Keepers::initialize(Universe& U_, lua_State* L_, int const nbKeepers_, int const gc_threshold_) +void Keepers::initialize(Universe& U_, lua_State* L_, size_t const nbKeepers_, int const gc_threshold_) { gc_threshold = gc_threshold_; @@ -945,7 +945,7 @@ void Keepers::initialize(Universe& U_, lua_State* L_, int const nbKeepers_, int U->callOnStateCreate(_K, L, LookupMode::ToKeeper); // _R[kLindasRegKey] = {} - kLindasRegKey.setValue(_K, [](lua_State* L_) { lua_newtable(L_); }); + kLindasRegKey.setValue(_K, [](lua_State* const L_) { lua_newtable(L_); }); STACK_CHECK(_K, 0); // configure GC last @@ -968,8 +968,8 @@ void Keepers::initialize(Universe& U_, lua_State* L_, int const nbKeepers_, int std::unique_ptr{ new(&U_) Keeper[nbKeepers_], DeleteKV{ &U_, nbKeepers_ } }, nbKeepers_ ); - for (int const _i : std::ranges::iota_view{ 0, nbKeepers_ }) { - _initOneKeeper(_kv.keepers[_i], _i); + for (size_t const _i : std::ranges::iota_view{ size_t{ 0 }, nbKeepers_ }) { + _initOneKeeper(_kv.keepers[_i], static_cast(_i)); } } } diff --git a/src/keeper.h b/src/keeper.h index e505361..74bdbf2 100644 --- a/src/keeper.h +++ b/src/keeper.h @@ -42,7 +42,7 @@ struct Keepers struct DeleteKV { Universe* U{}; - int count{}; + size_t count{}; void operator()(Keeper* k_) const; }; // can't use std::vector because Keeper contains a mutex, so we need a raw memory buffer @@ -65,7 +65,7 @@ struct Keepers void close(); [[nodiscard]] Keeper* getKeeper(KeeperIndex idx_); [[nodiscard]] int getNbKeepers() const; - void initialize(Universe& U_, lua_State* L_, int nbKeepers_, int gc_threshold_); + void initialize(Universe& U_, lua_State* L_, size_t nbKeepers_, int gc_threshold_); }; // ################################################################################################# diff --git a/src/lanes.cpp b/src/lanes.cpp index 3aef572..4ebe20c 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp @@ -805,14 +805,14 @@ static volatile int s_ecoc_go_ahead = 0; static void EnableCrashingOnCrashes(void) { if (InterlockedCompareExchange(&s_ecoc_initCount, 1, 0) == 0) { - typedef BOOL(WINAPI * tGetPolicy)(LPDWORD lpFlags); - typedef BOOL(WINAPI * tSetPolicy)(DWORD dwFlags); + using GetPolicy_t = BOOL(WINAPI *)(LPDWORD lpFlags); + using SetPolicy_t = BOOL(WINAPI *)(DWORD dwFlags); const DWORD EXCEPTION_SWALLOWING = 0x1; HMODULE _kernel32 = LoadLibraryA("kernel32.dll"); if (_kernel32) { - tGetPolicy pGetPolicy = (tGetPolicy) GetProcAddress(_kernel32, "GetProcessUserModeExceptionPolicy"); - tSetPolicy pSetPolicy = (tSetPolicy) GetProcAddress(_kernel32, "SetProcessUserModeExceptionPolicy"); + auto pGetPolicy{ (GetPolicy_t) (void*) GetProcAddress(_kernel32, "GetProcessUserModeExceptionPolicy") }; + auto pSetPolicy{ (SetPolicy_t) (void*) GetProcAddress(_kernel32, "SetProcessUserModeExceptionPolicy") }; if (pGetPolicy && pSetPolicy) { DWORD _dwFlags; if (pGetPolicy(&_dwFlags)) { diff --git a/src/state.cpp b/src/state.cpp index 4664486..27e595c 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -266,10 +266,10 @@ namespace state { break; } // open library - std::string_view const _libName{ _libs.substr(_prefixLen, _nameLen) }; + std::string_view const _libName{ _libs.substr(static_cast(_prefixLen), static_cast(_nameLen)) }; Open1Lib(_L, _libName); // advance to next item (can't do this earlier as it invalidates iterators) - _libs.remove_prefix(_prefixLen + _nameLen); + _libs.remove_prefix(static_cast(_prefixLen + _nameLen)); } lua_gc(_L, LUA_GCRESTART, 0); diff --git a/src/threading.cpp b/src/threading.cpp index 8ef41f5..ad3d3e4 100644 --- a/src/threading.cpp +++ b/src/threading.cpp @@ -87,14 +87,14 @@ THE SOFTWARE. * error in _this_ code. */ #if defined(PLATFORM_XBOX) || defined(PLATFORM_WIN32) || defined(PLATFORM_POCKETPC) -static void FAIL(char const* funcname, int rc) +static void FAIL(char const* funcname_, DWORD const rc_) { #if defined(PLATFORM_XBOX) - fprintf(stderr, "%s() failed! (%d)\n", funcname, rc); + fprintf(stderr, "%s() failed! (%d)\n", funcname_, rc_); #else // PLATFORM_XBOX char buf[256]; - FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, rc, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 256, nullptr); - fprintf(stderr, "%s() failed! [GetLastError() -> %d] '%s'", funcname, rc, buf); + FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, rc_, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 256, nullptr); + fprintf(stderr, "%s() failed! [GetLastError() -> %lu] '%s'", funcname_, rc_, buf); #endif // PLATFORM_XBOX #ifdef _MSC_VER __debugbreak(); // give a chance to the debugger! diff --git a/src/uniquekey.h b/src/uniquekey.h index 14b6d84..c409048 100644 --- a/src/uniquekey.h +++ b/src/uniquekey.h @@ -22,7 +22,12 @@ class UniqueKey { } // --------------------------------------------------------------------------------------------- - constexpr UniqueKey(UniqueKey const& rhs_) = default; + // rule of 5 + UniqueKey() = delete; + constexpr UniqueKey(UniqueKey const&) = default; + UniqueKey(UniqueKey&&) = delete; + UniqueKey& operator=(UniqueKey const&) = delete; + UniqueKey& operator=(UniqueKey&&) = delete; // debugName is irrelevant in comparisons inline constexpr std::weak_ordering operator<=>(UniqueKey const& rhs_) const { return storage <=> rhs_.storage; } inline constexpr auto operator==(UniqueKey const& rhs_) const { return storage == rhs_.storage; } diff --git a/src/universe.cpp b/src/universe.cpp index c435dad..7630e9c 100644 --- a/src/universe.cpp +++ b/src/universe.cpp @@ -170,7 +170,7 @@ void Universe::callOnStateCreate(lua_State* const L_, lua_State* const from_, Lo _U->selfdestructFirst = SELFDESTRUCT_END; _U->initializeAllocatorFunction(L_); _U->initializeOnStateCreate(L_); - _U->keepers.initialize(*_U, L_, _nbUserKeepers, _keepers_gc_threshold); + _U->keepers.initialize(*_U, L_, static_cast(_nbUserKeepers), _keepers_gc_threshold); STACK_CHECK(L_, 0); // Initialize 'timerLinda'; a common Linda object shared by all states -- cgit v1.2.3-55-g6feb