Boost C++ Libraries: Ticket #5190: boost::phoenix operator+ sometimes returns a reference to a temporary leading to undefined behaviour https://svn.boost.org/trac10/ticket/5190 <p> Compiling: </p> <pre class="wiki">const float x = 1.0f; const float y = 1.0f; std::cout &lt;&lt; (arg1+arg2)(x,y); </pre><p> with gcc results in the following warning: /usr/local/boost_1_45_0/boost/spirit/home/phoenix/operator/arithmetic.hpp:74: warning: returning reference to temporary </p> <p> The trouble is that result_of_plus&lt;const float, const float&gt;::type is const float&amp; instead of float. The source of the issue is that float is not supported "natively" by phoenix type deduction system ( if float is replaced by int, then the return type is correctly deduced ), the selected test overload is: </p> <pre class="wiki"> template &lt;typename X, typename Y&gt; typename disable_if&lt; is_basic&lt;X&gt; , x_reference_type &gt;::type test(X&amp;); </pre><p> As a result a reference to a temporary is returned that leads to undefined behaviour in programs compiled with heavy optimizations (-O3). </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5190 Trac 1.4.3 Thomas Heller Mon, 04 Apr 2011 17:26:06 GMT status, component changed; resolution set https://svn.boost.org/trac10/ticket/5190#comment:1 https://svn.boost.org/trac10/ticket/5190#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> <li><strong>component</strong> <span class="trac-field-old">spirit</span> → <span class="trac-field-new">phoenix</span> </li> </ul> Ticket