Boost C++ Libraries: Ticket #4538: Warning: dereferencing type-punned pointer will break strict-aliasing rules https://svn.boost.org/trac10/ticket/4538 <p> Hi, </p> <p> compiling the attached example with gcc-4.4.3 (Ubuntu 10.4, 64bit) with </p> <p> -Wall -O3 </p> <p> leads to a long warning message (second attachment), culminating in </p> <pre class="wiki">boost/1.44/include/boost/function/function_base.hpp:321: warning: dereferencing type-punned pointer will break strict-aliasing rules boost/1.44/include/boost/function/function_base.hpp:325: warning: dereferencing type-punned pointer will break strict-aliasing rules </pre><p> A way to avoid this warning is been suggested by Justin in the boost-users mailing list: </p> <p> <a class="ext-link" href="http://lists.boost.org/boost-users/2010/08/61564.php"><span class="icon">​</span>http://lists.boost.org/boost-users/2010/08/61564.php</a> </p> <p> Replace: </p> <pre class="wiki">reinterpret_cast&lt;functor_type*&gt;(&amp;in_buffer.data)-&gt;~Functor(); </pre><p> with: </p> <pre class="wiki">functor_type* p = reinterpret_cast&lt;functor_type*&gt;(&amp;in_buffer.data); p-&gt;~Functor(); </pre><p> (Second line with out_buffer, respectively) </p> <p> As noted by Emil Dotchevski in the thread on boost-users, it seems questionable why splitting up the original lines can get rid of the warning. So maybe a ticket should be filed for gcc by someone more knowledgeable than me. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4538 Trac 1.4.3 Roland Bock <rbock@…> Fri, 13 Aug 2010 08:37:26 GMT attachment set https://svn.boost.org/trac10/ticket/4538 https://svn.boost.org/trac10/ticket/4538 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">Spirit.cpp</span> </li> </ul> <p> Source code leading to said warning </p> Ticket Roland Bock <rbock@…> Fri, 13 Aug 2010 08:38:53 GMT attachment set https://svn.boost.org/trac10/ticket/4538 https://svn.boost.org/trac10/ticket/4538 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">log</span> </li> </ul> <p> Warning messages </p> Ticket sergey.belyashov@… Wed, 24 Nov 2010 13:59:50 GMT <link>https://svn.boost.org/trac10/ticket/4538#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4538#comment:1</guid> <description> <p> this is dublicate of Ticket <a class="new ticket" href="https://svn.boost.org/trac10/ticket/3780" title="#3780: Patches: Patch for disabling strict aliasing warnings, changing reinterpret_cast's (new)">#3780</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 17 Jan 2011 10:23:09 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4538#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4538#comment:2</guid> <description> <p> When will the patch be applied? This warning is very annoying to me because it causes pages of follow-up template errors. Is the suggested patch not considered a good fix to the problem? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Wed, 23 Mar 2011 00:34:36 GMT</pubDate> <title>owner changed https://svn.boost.org/trac10/ticket/4538#comment:3 https://svn.boost.org/trac10/ticket/4538#comment:3 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Douglas Gregor</span> to <span class="trac-author">Daniel James</span> </li> </ul> <p> Not sure who is maintaining function these days, let's try to volunteer Daniel James. :-) </p> Ticket sergey.belyashov@… Wed, 23 Mar 2011 07:37:22 GMT <link>https://svn.boost.org/trac10/ticket/4538#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4538#comment:4</guid> <description> <p> May be safer is to replace reinterpret_cast&lt;functor_type*&gt;(something) by static_cast&lt;functor_type*&gt;(static_cast&lt;void*&gt;(something))? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Daniel James</dc:creator> <pubDate>Wed, 23 Mar 2011 08:43:43 GMT</pubDate> <title>owner changed https://svn.boost.org/trac10/ticket/4538#comment:5 https://svn.boost.org/trac10/ticket/4538#comment:5 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Daniel James</span> to <span class="trac-author">No-Maintainer</span> </li> </ul> <p> No thanks. </p> Ticket Peter Dimov Wed, 23 Mar 2011 13:52:09 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4538#comment:6 https://svn.boost.org/trac10/ticket/4538#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> This is fixed by <a class="changeset" href="https://svn.boost.org/trac10/changeset/62621" title="Applied patch from #3618; fixes #3618">[62621]</a> in trunk, and by <a class="changeset" href="https://svn.boost.org/trac10/changeset/70361" title="Function: Merge from trunk. - Remove extra definition of operator(), ...">[70361]</a> in release. </p> Ticket