Subject: [Boost-bugs] [Boost C++ Libraries] #5098: [result_of] decltype-based result_of cannot handle rvalue-reference correctly
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-01-20 09:56:22
#5098: [result_of] decltype-based result_of cannot handle rvalue-reference
correctly
-------------------------------------+--------------------------------------
Reporter: mimomorin@⦠| Owner: no-maintainer
Type: Bugs | Status: new
Milestone: To Be Determined | Component: utility
Version: Boost Development Trunk | Severity: Problem
Keywords: result_of decltype |
-------------------------------------+--------------------------------------
The implementation of decltype-based boost::result_of is essentially the
same as
{{{
// This code is taken from N1454 (author: Douglas Gregor)
template <typename F, typename T1, typename T2, ..., typename TN>
class result_of<F(T1, T2, ..., TN)> {
static F f;
static T1 t1;
static T2 t2;
.
.
.
static TN tN;
public:
// Note: even if Ti is rvalue reference, ti is treated as lvalue.
typedef decltype(f(t1, t2, ..., tN)) type;
};
}}}
So, the implementation cannot handle rvalue-reference correctly (it
becomes lvalue).
For example, in the following code
{{{
struct func
{
unsigned char operator()(int&& ) { return 0; }
signed char operator()(int& ) { return 0; }
char operator()(int const&) { return 0; }
};
}}}
`boost::result_of<func(int)>::type` is `signed char` (which should be
`unsigned char`).
I will attach a patch for fixing this issue.
The patch uses `declval` rather than static members.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/5098> 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