[Boost-bugs] [Boost C++ Libraries] #5190: boost::phoenix operator+ sometimes returns a reference to a temporary leading to undefined behaviour

Subject: [Boost-bugs] [Boost C++ Libraries] #5190: boost::phoenix operator+ sometimes returns a reference to a temporary leading to undefined behaviour
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-02-14 17:49:08


#5190: boost::phoenix operator+ sometimes returns a reference to a temporary
leading to undefined behaviour
------------------------------------+---------------------------------------
 Reporter: nicos@… | Owner: djowel
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: spirit
  Version: Boost 1.45.0 | Severity: Showstopper
 Keywords: |
------------------------------------+---------------------------------------
 Compiling:
 {{{
 const float x = 1.0f;
 const float y = 1.0f;
 std::cout << (arg1+arg2)(x,y);
 }}}

 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

 The trouble is that result_of_plus<const float, const float>::type is
 const float& 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:
 {{{
     template <typename X, typename Y>
     typename disable_if<
         is_basic<X>
       , x_reference_type
>::type
     test(X&);
 }}}

 As a result a reference to a temporary is returned that leads to undefined
 behaviour in programs compiled with heavy optimizations (-O3).

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5190>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:05 UTC