boostorg / thread

Boost.org thread module
http://boost.org/libs/thread
198 stars 162 forks source link

Compiling with MSVC for ARM64 emits warning C4302 (truncation from 'void *const ' to 'long') #285

Closed wyattoday closed 5 years ago

wyattoday commented 5 years ago

When compiling with the latest Visual Studio (2019 -- 16.1.1) and targeting the app for ARM64, a warning is emitted when using a boost::mutex instance. Namely, here's the warning:

boost\thread\win32\basic_timed_mutex.hpp(271,1): warning C4302:  'type cast': truncation from 'void *const ' to 'long'

The fix is in boost/detail/interlocked.hpp (which I cannot find anywhere in the repositories, but is clearly a part of boost). Namely, on line 73 in interlocked.hpp, change this:

# if defined(_M_IA64) || defined(_M_AMD64) || defined(__x86_64__) || defined(__x86_64)

To this:

# if defined(_M_IX86) || defined(_M_IA64) || defined(_M_AMD64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_ARM) || defined(_M_ARM64)

Note that _M_IX86, _M_ARM, and _M_ARM64 are all checked and use intrinsics. This follows the documentation from Microsoft: _InterlockedCompareExchangePointer Intrinsic Functions

This change both fixes the warning for ARM64 apps, as well as uses the available and documented intrinsics for x86 apps.

I'd create a pull request for this, but I have no earthly idea where boost/detail/interlocked.hpp is in the repository.

viboes commented 5 years ago

This is a file from Boost.Winapi. Please create one on this module.