Boost C++ Libraries: Ticket #4127: warning break strict-aliasing rules https://svn.boost.org/trac10/ticket/4127 <p> Hello, under x86_64, using g++ 4.4.1 with '-W -Wall -O3' , when trying to compile the code below [code] #include "boost/make_shared.hpp" #include &lt;iostream&gt; </p> <p> int main(void) { </p> <blockquote> <p> boost::shared_ptr&lt;std::string&gt; x = boost::make_shared&lt;std::string&gt;("hello, world!"); std::cout &lt;&lt; *x; </p> </blockquote> <p> } <a href="https://svn.boost.org/trac10/code">code</a> (copied from make_shared doc) </p> <p> I get the folowing warnings: </p> <blockquote class="citation"> <blockquote class="citation"> <blockquote class="citation"> <p> boost/smart_ptr/make_shared.hpp:52: warning: dereferencing type-punned pointer will break strict-aliasing rules </p> </blockquote> </blockquote> </blockquote> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4127 Trac 1.4.3 Peter Dimov Sun, 25 Apr 2010 11:05:22 GMT <link>https://svn.boost.org/trac10/ticket/4127#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4127#comment:1</guid> <description> <p> This appears to be a bug in g++ 4.4's alias analysis. I can see a number of such issues marked as fixed in the GCC Bugzilla, so you might want to test again with 4.5. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 07 May 2010 13:38:10 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4127#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4127#comment:2</guid> <description> <p> I still got the warning with g++ 4.5.0 </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Matheus Martino</dc:creator> <pubDate>Fri, 16 Jul 2010 00:59:21 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4127#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4127#comment:3</guid> <description> <p> That warnings shows you that there is incompatibility betwen boost code and mingw optimization algorithm, it only hapens when using optimizations "-O2", "-O3" and "-Os", it don't hapens with optimizations "-O" and "-O1". If you get that warning, and think it is stoping your app from work, try to change the type of aptimization to "-O" or "-O1". </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 18 Nov 2010 02:45:17 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4127#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4127#comment:4</guid> <description> <p> Also occurs under linux on ubuntu 64 bit (10.04). It also occurs when using boost log (due to join main boost release?). My version of g++ is below: </p> <p> ubuntu:~/workspace/.metadata$ g++ -v </p> <p> Using built-in specs. </p> <p> Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5' --with-bugurl=<a class="ext-link" href="file:///usr/share/doc/gcc-4.4/README.Bugs"><span class="icon">​</span>file:///usr/share/doc/gcc-4.4/README.Bugs</a> --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 23 Feb 2011 23:49:57 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4127#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4127#comment:5</guid> <description> <p> Hi, the suggested fix from <a class="ext-link" href="http://tugll.tugraz.at/37921/weblog/12171.html"><span class="icon">​</span>http://tugll.tugraz.at/37921/weblog/12171.html</a> fixes the problem for me on windows with gcc (tdm64-1) 4.5.1 </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Thu, 24 Feb 2011 22:05:08 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4127#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4127#comment:6</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/69251" title="Apply suggested fix. Refs #4127.">[69251]</a>) Apply suggested fix. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4127" title="#4127: Bugs: warning break strict-aliasing rules (closed: fixed)">#4127</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Thu, 24 Feb 2011 22:05:34 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/4127#comment:7 https://svn.boost.org/trac10/ticket/4127#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Peter Dimov Tue, 22 Mar 2011 23:46:04 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4127#comment:8 https://svn.boost.org/trac10/ticket/4127#comment:8 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/70439" title="Merge [69251] to release. Fixes #4127.">[70439]</a>) Merge <a class="changeset" href="https://svn.boost.org/trac10/changeset/69251" title="Apply suggested fix. Refs #4127.">[69251]</a> to release. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4127" title="#4127: Bugs: warning break strict-aliasing rules (closed: fixed)">#4127</a>. </p> Ticket anonymous Tue, 18 Sep 2012 18:32:13 GMT <link>https://svn.boost.org/trac10/ticket/4127#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4127#comment:9</guid> <description> <p> I have another occurrence of this warning. I noticed that with -O1 there is no warning. No warning also if I remove -Wstrict-aliasing=2. </p> <p> In file included from /home/ededu/softs/ekiga/windows-mingww64/include/boost/function/detail/maybe_include.hpp:23:0, </p> <blockquote> <p> from /home/ededu/softs/ekiga/windows-mingww64/include/boost/function/function2.hpp:11, from /home/ededu/softs/ekiga/windows-mingww64/include/boost/signals/detail/named_slot_map.hpp:18, from /home/ededu/softs/ekiga/windows-mingww64/include/boost/signals/detail/signal_base.hpp:15, from /home/ededu/softs/ekiga/windows-mingww64/include/boost/signals/signal_template.hpp:23, from /home/ededu/softs/ekiga/windows-mingww64/include/boost/signals/signal0.hpp:24, from /home/ededu/softs/ekiga/windows-mingww64/include/boost/signal.hpp:19, from /home/ededu/softs/ekiga/windows-mingww64/include/boost/signals.hpp:9, from ../lib/engine/framework/services.h:47, from ekiga.h:46, from ekiga.cpp:41: </p> </blockquote> <p> /home/ededu/softs/ekiga/windows-mingww64/include/boost/function/function_template.hpp: In static member function ‘static R boost::detail::function::function_obj_invoker2&lt;<a class="missing wiki">FunctionObj</a>, R, T0, T1&gt;::invoke(boost::detail::function::function_buffer&amp;, T0, T1) [with <a class="missing wiki">FunctionObj</a> = boost::signals::detail::group_bridge_compare&lt;std::less&lt;int&gt;, int&gt;, R = bool, T0 = boost::signals::detail::stored_group, T1 = boost::signals::detail::stored_group]’: /home/ededu/softs/ekiga/windows-mingww64/include/boost/function/function_template.hpp:907:60: instantiated from ‘void boost::function2&lt;R, T1, T2&gt;::assign_to(Functor) [with Functor = boost::signals::detail::group_bridge_compare&lt;std::less&lt;int&gt;, int&gt;, R = bool, T0 = boost::signals::detail::stored_group, T1 = boost::signals::detail::stored_group]’ /home/ededu/softs/ekiga/windows-mingww64/include/boost/function/function_template.hpp:722:7: instantiated from ‘boost::function2&lt;R, T1, T2&gt;::function2(Functor, typename boost::enable_if_c&lt;boost::type_traits::ice_not&lt;boost::is_integral&lt;Functor&gt;::value&gt;::value, int&gt;::type) [with Functor = boost::signals::detail::group_bridge_compare&lt;std::less&lt;int&gt;, int&gt;, R = bool, T0 = boost::signals::detail::stored_group, T1 = boost::signals::detail::stored_group, typename boost::enable_if_c&lt;boost::type_traits::ice_not&lt;boost::is_integral&lt;Functor&gt;::value&gt;::value, int&gt;::type = int]’ /home/ededu/softs/ekiga/windows-mingww64/include/boost/signals/signal_template.hpp:197:53: instantiated from ‘boost::signal1&lt;R, T1, Combiner, Group, <a class="missing wiki">GroupCompare</a>, <a class="missing wiki">SlotFunction</a>&gt;::signal1(const Combiner&amp;, const <a class="missing wiki">GroupCompare</a>&amp;) [with R = void, T1 = boost::shared_ptr&lt;Ekiga::Service&gt;, Combiner = boost::last_value&lt;void&gt;, Group = int, <a class="missing wiki">GroupCompare</a> = std::less&lt;int&gt;, <a class="missing wiki">SlotFunction</a> = boost::function1&lt;void, boost::shared_ptr&lt;Ekiga::Service&gt; &gt;]’ ../lib/engine/framework/services.h:73:20: instantiated from here /home/ededu/softs/ekiga/windows-mingww64/include/boost/function/function_template.hpp:129:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] </p> <p> and others. So it seems function_template.hpp needs the same workaround. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 02 Oct 2012 13:26:52 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4127#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4127#comment:10</guid> <description> <p> Any comment on my previous comment? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 19 Oct 2012 13:52:56 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4127#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4127#comment:11</guid> <description> <p> Any comment, do you need other information? This generates maybe 150 warning lines per file compiled... </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Fri, 19 Oct 2012 14:16:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4127#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4127#comment:12</guid> <description> <p> Have you verified that the same workaround works for function_template? </p> <p> In either case, this problem is no longer about smart_ptr, so I suggest you create another ticket with "function" as the component and put the information there. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 05 Nov 2012 11:02:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4127#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4127#comment:13</guid> <description> <p> The fix in comment 6 does not apply, since there the fix was to cut the redirection in two, but in my case there is no redirection. </p> <p> I have warnings in function_template, signal_template and function_base. I wait for gcc 4.7 on my distro and create a new bug report if it still applies. </p> </description> <category>Ticket</category> </item> </channel> </rss>