chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.88k stars 1.21k forks source link

MSVC 14.2 compilation "warning C4242: '=': conversion from 'int' to 'ADDRESS_FAMILY', possible loss of data" #697

Open ghost opened 3 years ago

ghost commented 3 years ago

@wyattoday commented on May 30, 2019, 12:49 PM UTC:

When compiling an app using ASIO and a newer version of Visual Studio (for example, VS 2019) a bunch of warnings are emitted:

boost\asio\detail\impl\win_iocp_socket_service_base.ipp(609,32): warning C4242:  '=': conversion from 'int' to 'ADDRESS_FAMILY', possible loss of data (compiling source file XYZ.cpp)

The solution is, on line 609 of win_iocp_socket_service_base.ipp, change the line to this:

a.base.sa_family = static_cast<ADDRESS_FAMILY>(family);

Similarly, in boost\asio\impl\serial_port_base.ipp(511,28): warning C4242: '=': conversion from 'const unsigned int' to 'BYTE', possible loss of data (compiling source file GlobalVars.cpp):

Fix:

  storage.ByteSize = static_cast<BYTE>(value_);

This issue was moved by chriskohlhoff from boostorg/asio#246.

ghost commented 3 years ago

@fsmoke commented on May 7, 2020, 9:17 AM UTC:

I have the same issue - VS 2019 - x86 project configuration

Bynun commented 5 days ago

I'm still getting both of those issues mentioned in the first post... Visual Studio v17.7.7 (latest update as of this post) Boost v1.86.0 (again, the latest)

Give it's not been fixed in the code and rarely mentioned am i missing some pre step for the ASIO which would of prevented this error as i'm using the headers directly from the download, or is it just a windows issue that most people just ignore?