Boost C++ Libraries: Ticket #9440: Spurious compilation failures on GCC 4.7.2 https://svn.boost.org/trac10/ticket/9440 <p> I have a large project which uses Boost.Intrusive containers and some components of Boost.Interprocess, which also rely on Boost.Intrusive. When built on Debian Wheezy with GCC 4.7.2 (the stock version from the distribution repository) I get compilation failures, such as: </p> <pre class="wiki">In file included from /usr/include/boost/intrusive/detail/utilities.hpp:17:0, from /usr/include/boost/intrusive/options.hpp:20, from /home/lastique/src/xcoder/trunk/src/pipeline/pipelineI.h:16, from /home/lastique/src/xcoder/trunk/src/pipeline/pipelineI.cpp:1: /usr/include/boost/intrusive/pointer_traits.hpp: In instantiation of ‘static T* boost::intrusive::pointer_traits&lt;T*&gt;::static_cast_from(U*) [with U = const void; T = boost::intrusive::bhtraits&lt;Pipeline_i::wrapper_info, boost::intrusive::rbtree_node_traits&lt;void*, true&gt;, (boost::intrusive::link_mode_type)2u, for_wrapper_info_lookup_by_token, 3u&gt;; boost::intrusive::pointer_traits&lt;T*&gt;::pointer = boost::intrusive::bhtraits&lt;Pipeline_i::wrapper_info, boost::intrusive::rbtree_node_traits&lt;void*, true&gt;, (boost::intrusive::link_mode_type)2u, for_wrapper_info_lookup_by_token, 3u&gt;*]’: /usr/include/boost/intrusive/detail/tree_node.hpp:168:94: required from ‘boost::intrusive::tree_iterator&lt;RealValueTraits, IsConst&gt;::const_real_value_traits_ptr boost::intrusive::tree_iterator&lt;RealValueTraits, IsConst&gt;::get_real_value_traits() const [with RealValueTraits = boost::intrusive::bhtraits&lt;Pipeline_i::wrapper_info, boost::intrusive::rbtree_node_traits&lt;void*, true&gt;, (boost::intrusive::link_mode_type)2u, for_wrapper_info_lookup_by_token, 3u&gt;; bool IsConst = false; boost::intrusive::tree_iterator&lt;RealValueTraits, IsConst&gt;::const_real_value_traits_ptr = const boost::intrusive::bhtraits&lt;Pipeline_i::wrapper_info, boost::intrusive::rbtree_node_traits&lt;void*, true&gt;, (boost::intrusive::link_mode_type)2u, for_wrapper_info_lookup_by_token, 3u&gt;*]’ /usr/include/boost/intrusive/detail/tree_node.hpp:118:70: required from ‘boost::intrusive::tree_iterator&lt;RealValueTraits, IsConst&gt;::tree_iterator(const boost::intrusive::tree_iterator&lt;RealValueTraits, false&gt;&amp;) [with RealValueTraits = boost::intrusive::bhtraits&lt;Pipeline_i::wrapper_info, boost::intrusive::rbtree_node_traits&lt;void*, true&gt;, (boost::intrusive::link_mode_type)2u, for_wrapper_info_lookup_by_token, 3u&gt;; bool IsConst = false]’ /home/lastique/src/xcoder/trunk/src/pipeline/pipelineI.cpp:557:80: required from here /usr/include/boost/intrusive/pointer_traits.hpp:245:39: error: static_cast from type ‘const void*’ to type ‘boost::intrusive::pointer_traits&lt;boost::intrusive::bhtraits&lt;Pipeline_i::wrapper_info, boost::intrusive::rbtree_node_traits&lt;void*, true&gt;, (boost::intrusive::link_mode_type)2u, for_wrapper_info_lookup_by_token, 3u&gt;*&gt;::pointer {aka boost::intrusive::bhtraits&lt;Pipeline_i::wrapper_info, boost::intrusive::rbtree_node_traits&lt;void*, true&gt;, (boost::intrusive::link_mode_type)2u, for_wrapper_info_lookup_by_token, 3u&gt;*}’ casts away qualifiers </pre><p> and </p> <pre class="wiki">In file included from /home/lastique/src/xcoder/trunk/src/workers/picture2video/picturecache-index.h:20:0, from /home/lastique/src/xcoder/trunk/src/workers/picture2video/picturecache-index.cpp:18: /usr/include/boost/intrusive/list.hpp: In instantiation of ‘boost::intrusive::list_impl&lt;ValueTraits, SizeType, ConstantTimeSize&gt;::const_real_value_traits_ptr boost::intrusive::list_impl&lt;ValueTraits, SizeType, ConstantTimeSize&gt;::real_value_traits_ptr() const [with ValueTraits = boost::intrusive::mhtraits&lt;picture_cache_index::cache_element, boost::intrusive::list_member_hook&lt;boost::intrusive::void_pointer&lt;boost::interprocess::offset_ptr&lt;void&gt; &gt; &gt;, &amp;picture_cache_index::cache_element::lru_list_hook&gt;; SizeType = long unsigned int; bool ConstantTimeSize = true; boost::intrusive::list_impl&lt;ValueTraits, SizeType, ConstantTimeSize&gt;::const_real_value_traits_ptr = boost::interprocess::offset_ptr&lt;const boost::intrusive::mhtraits&lt;picture_cache_index::cache_element, boost::intrusive::list_member_hook&lt;boost::intrusive::void_pointer&lt;boost::interprocess::offset_ptr&lt;void&gt; &gt; &gt;, &amp;picture_cache_index::cache_element::lru_list_hook&gt;, long int, long unsigned int, 0ul&gt;]’: /usr/include/boost/intrusive/list.hpp:1264:85: required from ‘boost::intrusive::list_impl&lt;ValueTraits, SizeType, ConstantTimeSize&gt;::iterator boost::intrusive::list_impl&lt;ValueTraits, SizeType, ConstantTimeSize&gt;::iterator_to(boost::intrusive::list_impl&lt;ValueTraits, SizeType, ConstantTimeSize&gt;::reference) [with ValueTraits = boost::intrusive::mhtraits&lt;picture_cache_index::cache_element, boost::intrusive::list_member_hook&lt;boost::intrusive::void_pointer&lt;boost::interprocess::offset_ptr&lt;void&gt; &gt; &gt;, &amp;picture_cache_index::cache_element::lru_list_hook&gt;; SizeType = long unsigned int; bool ConstantTimeSize = true; boost::intrusive::list_impl&lt;ValueTraits, SizeType, ConstantTimeSize&gt;::iterator = boost::intrusive::list_iterator&lt;boost::intrusive::mhtraits&lt;picture_cache_index::cache_element, boost::intrusive::list_member_hook&lt;boost::intrusive::void_pointer&lt;boost::interprocess::offset_ptr&lt;void&gt; &gt; &gt;, &amp;picture_cache_index::cache_element::lru_list_hook&gt;, false&gt;; typename boost::intrusive::detail::get_real_value_traits&lt;ValueTraits&gt;::type = boost::intrusive::mhtraits&lt;picture_cache_index::cache_element, boost::intrusive::list_member_hook&lt;boost::intrusive::void_pointer&lt;boost::interprocess::offset_ptr&lt;void&gt; &gt; &gt;, &amp;picture_cache_index::cache_element::lru_list_hook&gt;; boost::intrusive::list_impl&lt;ValueTraits, SizeType, ConstantTimeSize&gt;::reference = picture_cache_index::cache_element&amp;]’ /home/lastique/src/xcoder/trunk/src/workers/picture2video/picturecache-index.cpp:235:31: required from here /usr/include/boost/intrusive/list.hpp:183:99: error: no matching function for call to ‘boost::intrusive::pointer_traits&lt;boost::interprocess::offset_ptr&lt;boost::intrusive::mhtraits&lt;picture_cache_index::cache_element, boost::intrusive::list_member_hook&lt;boost::intrusive::void_pointer&lt;boost::interprocess::offset_ptr&lt;void&gt; &gt; &gt;, &amp;picture_cache_index::cache_element::lru_list_hook&gt;, long int, long unsigned int, 0ul&gt; &gt;::pointer_to(const real_value_traits&amp;)’ /usr/include/boost/intrusive/list.hpp:183:99: note: candidate is: In file included from /usr/include/boost/interprocess/allocators/allocator.hpp:21:0, from /home/lastique/src/xcoder/trunk/src/workers/picture2video/picturecache-index.cpp:12: /usr/include/boost/intrusive/pointer_traits.hpp:94:19: note: static boost::intrusive::pointer_traits&lt;Ptr&gt;::pointer boost::intrusive::pointer_traits&lt;Ptr&gt;::pointer_to(boost::intrusive::pointer_traits&lt;Ptr&gt;::reference) [with Ptr = boost::interprocess::offset_ptr&lt;boost::intrusive::mhtraits&lt;picture_cache_index::cache_element, boost::intrusive::list_member_hook&lt;boost::intrusive::void_pointer&lt;boost::interprocess::offset_ptr&lt;void&gt; &gt; &gt;, &amp;picture_cache_index::cache_element::lru_list_hook&gt;, long int, long unsigned int, 0ul&gt;; boost::intrusive::pointer_traits&lt;Ptr&gt;::pointer = boost::interprocess::offset_ptr&lt;boost::intrusive::mhtraits&lt;picture_cache_index::cache_element, boost::intrusive::list_member_hook&lt;boost::intrusive::void_pointer&lt;boost::interprocess::offset_ptr&lt;void&gt; &gt; &gt;, &amp;picture_cache_index::cache_element::lru_list_hook&gt;, long int, long unsigned int, 0ul&gt;; boost::intrusive::pointer_traits&lt;Ptr&gt;::reference = boost::intrusive::mhtraits&lt;picture_cache_index::cache_element, boost::intrusive::list_member_hook&lt;boost::intrusive::void_pointer&lt;boost::interprocess::offset_ptr&lt;void&gt; &gt; &gt;, &amp;picture_cache_index::cache_element::lru_list_hook&gt;&amp;] /usr/include/boost/intrusive/pointer_traits.hpp:94:19: note: no known conversion for argument 1 from ‘const real_value_traits {aka const boost::intrusive::mhtraits&lt;picture_cache_index::cache_element, boost::intrusive::list_member_hook&lt;boost::intrusive::void_pointer&lt;boost::interprocess::offset_ptr&lt;void&gt; &gt; &gt;, &amp;picture_cache_index::cache_element::lru_list_hook&gt;}’ to ‘boost::intrusive::pointer_traits&lt;boost::interprocess::offset_ptr&lt;boost::intrusive::mhtraits&lt;picture_cache_index::cache_element, boost::intrusive::list_member_hook&lt;boost::intrusive::void_pointer&lt;boost::interprocess::offset_ptr&lt;void&gt; &gt; &gt;, &amp;picture_cache_index::cache_element::lru_list_hook&gt;, long int, long unsigned int, 0ul&gt; &gt;::reference {aka boost::intrusive::mhtraits&lt;picture_cache_index::cache_element, boost::intrusive::list_member_hook&lt;boost::intrusive::void_pointer&lt;boost::interprocess::offset_ptr&lt;void&gt; &gt; &gt;, &amp;picture_cache_index::cache_element::lru_list_hook&gt;&amp;}’ </pre><p> To my understanding the problem is caused by a compiler bug, which only manifests itself under some unknown and specific conditions. I could not reproduce it with a small code sample, and the same project (with the same Boost 1.55) compiles without problems with GCC 4.4.5 and 4.8.1 on Debian Squeeze and Kubuntu 13.10, respectively. </p> <p> The problem is that the compiler sometimes instantiates pointer_traits with an incorrect pointer type, which is missing the const qualifier in the element type (i.e. pointer_traits&lt;foo*&gt; instead of pointer_traits&lt;const foo*&gt;). It happens with both raw and smart pointers, as seen in the errors above. I don't know how it happens, the relevant code of Boost.Intrusive seem correct to me. </p> <p> I have prepared a patch that works around this problem for me. Basically, I replaced the instantiation of pointer_traits in the problematic places with calls to free functions that instantiate pointer_traits themselves. With this patch applied, the project compiles without errors. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9440 Trac 1.4.3 Andrey Semashev Wed, 27 Nov 2013 12:39:25 GMT attachment set https://svn.boost.org/trac10/ticket/9440 https://svn.boost.org/trac10/ticket/9440 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">intrusive_gcc47_drops_qualifiers.patch</span> </li> </ul> <p> The patch works around compilation failures with GCC 4.7.2. </p> Ticket Ion Gaztañaga Fri, 14 Feb 2014 13:39:32 GMT <link>https://svn.boost.org/trac10/ticket/9440#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9440#comment:1</guid> <description> <p> pointer_to is used more than 100 times the library and we are not sure if this would fix the problem as the compiler bug might appear in other places. Could you test if this problem is also present with the latest GCC 4.7 (4.7.3)? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Fri, 14 Feb 2014 15:20:02 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9440#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9440#comment:2</guid> <description> <p> Updating to GCC 4.7.3 is rather problematic since the Debian Wheezy machine is actually a corporate server which I cannot upgrade. I could try creating a virtual machine with Debian Jessie which has 4.7.3, but that would take a lot of time, I can't tell when I'm able to do it. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 18 Feb 2014 06:43:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9440#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9440#comment:3</guid> <description> <p> +1 Confirmed at Raspberry Pi toolchain with 4.7.2 </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 04 Mar 2014 16:15:07 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9440#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9440#comment:4</guid> <description> <p> confirmed on ubuntu 4.7.2 . same problem about not being able to update/change gcc </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Wed, 17 Dec 2014 14:52:14 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/9440#comment:5 https://svn.boost.org/trac10/ticket/9440#comment:5 <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">wontfix</span> </li> </ul> <p> Sorry for not being able to dedicate resources to this. Closing as wontfix. </p> Ticket