Subject: Re: [Boost-bugs] [Boost C++ Libraries] #12773: WINDOWS- Boost thread 1.63.0 strict aliasing warnings
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-02-19 13:29:04
#12773: WINDOWS- Boost thread 1.63.0 strict aliasing warnings
--------------------------------+----------------------
Reporter: alexandre.nunes@⦠| Owner: anthonyw
Type: Bugs | Status: new
Milestone: To Be Determined | Component: thread
Version: Boost 1.63.0 | Severity: Problem
Resolution: | Keywords:
--------------------------------+----------------------
Comment (by alexandre.nunes@â¦):
You're absolutely right that type-punning leads to UB, and so does current
implementation. It seems to me that other than checking member-by-member,
the other option would be to - providing the structure is sufficiently
sane - use std::memcmp() to check the data. Most compilers can optimize
the call away, when that's safe.
Here's the compiler report:
{{{
gcc.compile.c++ bin.v2/libs/type_erasure/build/gcc-mingw-6.3/release
/link-static/runtime-link-static/target-os-windows/threadapi-win32
/threading-multi/dynamic_binding.o
In file included from ./boost/thread/shared_mutex.hpp:18:0,
from libs/type_erasure/src/dynamic_binding.cpp:14:
./boost/thread/win32/shared_mutex.hpp: In instantiation of 'T
boost::shared_mutex::interlocked_compare_exchange(T*, T, T) [with T =
boost::shared_mutex::state_data]':
./boost/thread/win32/shared_mutex.hpp:130:103: required from here
./boost/thread/win32/shared_mutex.hpp:51:63: error: dereferencing
type-punned pointer will break strict-aliasing rules [-Werror=strict-
aliasing]
*reinterpret_cast<long*>(&new_value),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./boost/thread/win32/shared_mutex.hpp:52:63: error: dereferencing
type-punned pointer will break strict-aliasing rules [-Werror=strict-
aliasing]
*reinterpret_cast<long*>(&comparand));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./boost/thread/win32/shared_mutex.hpp:53:20: error: dereferencing
type-punned pointer will break strict-aliasing rules [-Werror=strict-
aliasing]
return *reinterpret_cast<T const*>(&res);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./boost/thread/win32/shared_mutex.hpp:53:52: error: dereferencing
type-punned pointer will break strict-aliasing rules [-Werror=strict-
aliasing]
return *reinterpret_cast<T const*>(&res);
^
cc1plus: some warnings being treated as errors
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/12773#comment:5> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-19 13:33:12 UTC