Boost C++ Libraries: Ticket #12162: buffer interface violates strict-aliasing rule https://svn.boost.org/trac10/ticket/12162 <p> The buffer class interfaces can cause violations of the strict-aliasing rule. This example program emits this warning when compiled with optimizations on GCC 5.1.1: </p> <pre class="wiki">#include &lt;boost/asio/streambuf.hpp&gt; #include &lt;boost/endian/buffers.hpp&gt; #include &lt;cstdint&gt; #include &lt;memory&gt; template&lt;class Streambuf&gt; std::uint16_t get(Streambuf&amp; sb) { using namespace boost::asio; using namespace boost::endian; std::uint8_t b[2]; sb.consume(buffer_copy(buffer(b), sb.data())); return reinterpret_cast&lt;big_uint16_buf_t const*&gt;(&amp;b[0])-&gt;value(); } int main() { using namespace boost::asio; streambuf sb; std::uint8_t b[2]; memset(&amp;b[0], 0, sizeof(b)); sb.commit(buffer_copy(sb.prepare(sizeof(b)), buffer(b))); return get(sb); } </pre><p> Produces: </p> <pre class="wiki">prog.cc: In instantiation of 'uint16_t get(Streambuf&amp;) [with Streambuf = boost::asio::basic_streambuf&lt;&gt;; uint16_t = short unsigned int]': prog.cc:24:18: required from here prog.cc:14:67: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] return reinterpret_cast&lt;big_uint16_buf_t const*&gt;(&amp;b[0])-&gt;value(); </pre><p> Link to program and output: <a class="ext-link" href="http://melpon.org/wandbox/permlink/x7xQsxaU3jv0lOtD"><span class="icon">​</span>http://melpon.org/wandbox/permlink/x7xQsxaU3jv0lOtD</a> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12162 Trac 1.4.3