Boost C++ Libraries: Ticket #11044: boost::rv inherits off union, when such passed as template argument https://svn.boost.org/trac10/ticket/11044 <p> Consider the following minimal reproducer: </p> <pre class="wiki">template&lt;typename T&gt; struct wrap { typedef T type; }; template &lt;class T&gt; class rv: public wrap &lt;T&gt;::type {}; template &lt;class value_type&gt; struct circular_buffer { typedef const value_type&amp; param_value_type; typedef rv&lt; value_type &gt;&amp; rvalue_type; void push_back(param_value_type item) {} void push_back(rvalue_type item) {} }; union U { int i; char c; }; void f(circular_buffer&lt;U&gt; b, const U&amp; u) { b.push_back(u); } </pre><p> Certain GCC 5.0's had a bug where rv would be instantiated, even though it doesn't have to be (so I am told), which uncovered the latent bug in Boost that rv inherits off union when given one. </p> <p> Proposed patch: </p> <pre class="wiki">diff -up ./move/core.hpp~ ./move/core.hpp --- boost/move/core.hpp~ 2015-02-09 17:33:35.000000000 +0100 +++ boost/move/core.hpp 2015-02-13 13:54:52.012130813 +0100 @@ -43,6 +43,7 @@ #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) &amp;&amp; !defined(BOOST_MOVE_DOXYGEN_INVOKED) #include &lt;boost/move/detail/meta_utils.hpp&gt; + #include &lt;boost/type_traits/is_class.hpp&gt; //Move emulation rv breaks standard aliasing rules so add workarounds for some compilers #if defined(__GNUC__) &amp;&amp; (__GNUC__ &gt;= 4) &amp;&amp; \ @@ -65,7 +66,7 @@ template &lt;class T&gt; class rv : public ::boost::move_detail::if_c - &lt; ::boost::move_detail::is_class_or_union&lt;T&gt;::value + &lt; ::boost::is_class&lt;T&gt;::value , T , ::boost::move_detail::nat &gt;::type </pre><p> I regtested this on x86_64 using GCC 5.0.0, and noted no regressions. However I'm not sure if pulling in type traits like this is admissible--I mean, why else reimplement is_class_or_union in Boost.Move? Historical reasons? </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11044 Trac 1.4.3 Ion Gaztañaga Mon, 23 Feb 2015 21:33:39 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/11044#comment:1 https://svn.boost.org/trac10/ticket/11044#comment:1 <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> Hi, </p> <p> In current master and develop branches it inherits from boost::move::is_class. Custom traits are used to avoid many dependencies brought by Boost.<a class="missing wiki">TypeTraits</a> (MPL, Preprocessor...). This should change when the new version of dependency-free is released (see <a class="ext-link" href="http://comments.gmane.org/gmane.comp.lib.boost.devel/256808"><span class="icon">​</span>http://comments.gmane.org/gmane.comp.lib.boost.devel/256808</a>). </p> Ticket Petr Machata <pmachata@…> Tue, 24 Feb 2015 21:43:14 GMT <link>https://svn.boost.org/trac10/ticket/11044#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11044#comment:2</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/11044#comment:1" title="Comment 1">igaztanaga</a>: </p> <blockquote class="citation"> <p> In current master and develop branches it inherits from boost::move::is_class. </p> </blockquote> <p> Oh, cool. I must have forgotten to sync the git tree before checking. </p> <blockquote class="citation"> <p> Custom traits are used to avoid many dependencies brought by Boost.<a class="missing wiki">TypeTraits</a>. </p> </blockquote> <p> That's what I suspected. Thanks for taking care of this! </p> </description> <category>Ticket</category> </item> </channel> </rss>