boostorg / winapi

Windows API declarations without <windows.h>, for internal Boost use.
63 stars 55 forks source link

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

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. 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.

Originally reported over here: https://github.com/boostorg/thread/issues/285