Opened 9 years ago

Closed 8 years ago

#9550 closed Bugs (fixed)

gcc warn will break strict-aliasing rule in win_iocp_handle_service.ipp:49

Reported by: anonymous Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.55.0 Severity: Problem
Keywords: Cc:

Description

In file included from C:/boost_1_55_0/boost/asio/detail/win_iocp_handle_service.hpp:319:0,
                 from C:/boost_1_55_0/boost/asio/detail/win_iocp_serial_port_service.hpp:26,
                 from C:/boost_1_55_0/boost/asio/serial_port_service.hpp:27,
                 from C:/boost_1_55_0/boost/asio/basic_serial_port.hpp:30,
                 from C:/boost_1_55_0/boost/asio/serial_port.hpp:24,
C:/boost_1_55_0/boost/asio/detail/impl/win_iocp_handle_service.ipp: In constructor 
'boost::asio::detail::win_iocp_handle_service::overlapped_wrapper::overlapped_wrapper(boost::system::error_code&)':
C:/boost_1_55_0/boost/asio/detail/impl/win_iocp_handle_service.ipp:49:44: warning: 
dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
       *reinterpret_cast<DWORD_PTR*>(&hEvent) |= 1;

I think that this problem can resolve by via lvalue char* type.

char* comply_strict_aliasing_rule = reinterpret_cast<char*>(&hEvent);
*reinterpret_cast<DWORD_PTR*>(comply_strict_aliasing_rule) |= 1;

Change History (2)

comment:1 by Steven Watanabe, 9 years ago

Adding an intermediate cast doesn't make the code any more correct, although it may eliminate the warning.

comment:2 by chris_kohlhoff, 8 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.