Boost C++ Libraries: Ticket #12806: flat_map.hpp function force_copy break strict-aliasing on gcc < 4.4 https://svn.boost.org/trac10/ticket/12806 <p> Hello! </p> <p> On function (<a class="ext-link" href="https://github.com/boostorg/container/blob/develop/include/boost/container/flat_map.hpp#L61"><span class="icon">​</span>https://github.com/boostorg/container/blob/develop/include/boost/container/flat_map.hpp#L61</a>): </p> <pre class="wiki">template&lt;class D, class S&gt; BOOST_CONTAINER_FORCEINLINE static D force_copy(S s) { D *vp = reinterpret_cast&lt;D *&gt;(&amp;s); return D(*vp); } </pre><p> gcc 4.3.4 (SLE 11) produced wrong code. It seems that the compiler does not create a copy of an object "s" and returns an object of D(). </p> <p> If I change the signature of function on "BOOST_CONTAINER_FORCEINLINE static D force_copy(const S&amp; s)" the code works and the tests pass. But then does not create a copy of an object "s" in a function call. </p> <p> I'm not sure that this change is correct. Is there any other workaround for this problem with a compiler gcc 4.3 or better disable strict-aliasing? </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12806 Trac 1.4.3 Ion Gaztañaga Sun, 09 Apr 2017 20:38:53 GMT <link>https://svn.boost.org/trac10/ticket/12806#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12806#comment:1</guid> <description> <p> Sorry for the long delay. Catching by const reference should not be a problem. I'll try to test it in several compilers. </p> </description> <category>Ticket</category> </item> </channel> </rss>