From fbb878c4db8267941b4094f81b569c2be086fd1a Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Wed, 17 Jan 2024 09:51:29 +0200 Subject: [PATCH] Fix compiler warnings * Avoid reinterpret_cast * Remove pointless #define _GNU_SOURCE. It is already defined by gyp, and defining it after all the includes does nothing anyway. * Avoid using Nothing for primitives, they are not initialized. * unary minus operator applied to unsigned type, result still unsigned * overriding '/GR-' with '/GR' --- binding.gyp | 3 ++- src/external_copy/serializer_nortti.cc | 4 ++-- src/isolate/allocator_nortti.cc | 2 +- src/isolate/environment.cc | 1 - src/module/lib_handle.cc | 7 ++++++- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/binding.gyp b/binding.gyp index 0fc35f02..247d4284 100644 --- a/binding.gyp +++ b/binding.gyp @@ -14,7 +14,8 @@ }, 'msvs_settings': { 'VCCLCompilerTool': { - 'AdditionalOptions': [ '-std:c++17', '/GR' ], + 'AdditionalOptions': [ '-std:c++17' ], + 'RuntimeTypeInfo': 'true', 'ExceptionHandling': '1', }, }, diff --git a/src/external_copy/serializer_nortti.cc b/src/external_copy/serializer_nortti.cc index f2ce0981..3f280f80 100644 --- a/src/external_copy/serializer_nortti.cc +++ b/src/external_copy/serializer_nortti.cc @@ -18,7 +18,7 @@ void SerializerDelegate::ThrowDataCloneError(Local message) { auto SerializerDelegate::GetSharedArrayBufferId( Isolate* /*isolate*/, Local shared_array_buffer) -> Maybe { - auto result = Nothing(); + auto result = Just(0); detail::RunBarrier([&]() { transferables.emplace_back(std::make_unique(shared_array_buffer)); result = Just(transferables.size() - 1); @@ -34,7 +34,7 @@ auto SerializerDelegate::GetWasmModuleTransferId( } auto SerializerDelegate::WriteHostObject(Isolate* /*isolate*/, Local object) -> Maybe { - auto result = Nothing(); + auto result = Just(false); detail::RunBarrier([&]() { serializer->WriteUint32(transferables.size()); transferables.emplace_back(TransferOut(object)); diff --git a/src/isolate/allocator_nortti.cc b/src/isolate/allocator_nortti.cc index c17a6684..e6f031d0 100644 --- a/src/isolate/allocator_nortti.cc +++ b/src/isolate/allocator_nortti.cc @@ -21,7 +21,7 @@ class ExternalMemoryHandle { ~ExternalMemoryHandle() { auto* allocator = IsolateEnvironment::GetCurrent()->GetLimitedAllocator(); if (allocator != nullptr) { - allocator->AdjustAllocatedSize(-size); + allocator->AdjustAllocatedSize(-static_cast(size)); } }; diff --git a/src/isolate/environment.cc b/src/isolate/environment.cc index bfbbce7e..ac0d94a6 100644 --- a/src/isolate/environment.cc +++ b/src/isolate/environment.cc @@ -55,7 +55,6 @@ static auto GetStackBase() -> void* { return base; } #elif defined __unix__ -#define _GNU_SOURCE static auto GetStackBase() -> void* { pthread_t self = pthread_self(); pthread_attr_t attrs; diff --git a/src/module/lib_handle.cc b/src/module/lib_handle.cc index c824367f..5177e760 100644 --- a/src/module/lib_handle.cc +++ b/src/module/lib_handle.cc @@ -54,8 +54,13 @@ auto LibHandle::Hrtime(MaybeLocal maybe_diff) -> Local { auto LibHandle::PrivateSymbol(MaybeLocal maybe_name) -> Local { Local name{}; if (maybe_name.ToLocal(&name)) { /* nothing */ } + union { + Local *symbol; + Local *value; + } cast; auto symbol = Private::New(Isolate::GetCurrent(), name); - return *reinterpret_cast*>(&symbol); + cast.symbol = &symbol; + return *cast.value; } // NOLINTNEXTLINE(readability-convert-member-functions-to-static)