diff --git a/include/boost/multiprecision/detail/et_ops.hpp b/include/boost/multiprecision/detail/et_ops.hpp index a72dee90..3778e010 100644 --- a/include/boost/multiprecision/detail/et_ops.hpp +++ b/include/boost/multiprecision/detail/et_ops.hpp @@ -11,12 +11,19 @@ namespace boost{ namespace multiprecision{ // // Non-member operators for number: // -// Unary operators first: +// Unary operators first. +// Note that these *must* return by value, even though that's somewhat against +// existing practice. The issue is that in C++11 land one could easily and legitimately +// write: +// auto x = +1234_my_user_defined_suffix; +// which would result in a dangling-reference-to-temporary if unary + returned a reference +// to it's argument. While return-by-value is obviously inefficient in other situations +// the reality is that no one ever uses unary operator+ anyway...! // template -inline BOOST_CONSTEXPR const number& operator + (const number& v) { return v; } +inline BOOST_CONSTEXPR const number operator + (const number& v) { return v; } template -inline BOOST_CONSTEXPR const detail::expression& operator + (const detail::expression& v) { return v; } +inline BOOST_CONSTEXPR const detail::expression operator + (const detail::expression& v) { return v; } template inline detail::expression > operator - (const number& v) {