Odd Warning in transform_iterator.hpp ?

I'm using the current Boost library on Microsoft Visual Studio 2005. I'm getting a warning on line 121 of transform_iterator.hpp, complaining "returning address of local variable or temporary". The line in question is the body of this function: typename super_t::reference dereference() const { return m_f(*this->base()); } My m_f supplied to the template is ordinary enough; it returns a value. The exact same situation in a unit test gives no complaint! Any idea what this is all about?

I'm using the current Boost library on Microsoft Visual Studio 2005. I'm getting a warning on line 121 of transform_iterator.hpp, complaining "returning address of local variable or temporary". The line in question is the body of this function:
typename super_t::reference dereference() const { return m_f(*this->base()); }
My m_f supplied to the template is ordinary enough; it returns a value.
Is your m_f a function object that uses result_of protocol to declare
its return value?
It may be that while its operator() returns a value, its result<> is telling
transform_iterator that it returns a reference.
For example, if its result<> looks like this:
template <typename> struct result;
template

On 7/28/2011 4:10 AM, Nathan Ridge wrote:
I'm using the current Boost library on Microsoft Visual Studio 2005. I'm getting a warning on line 121 of transform_iterator.hpp, complaining "returning address of local variable or temporary". The line in question is the body of this function:
typename super_t::reference dereference() const { return m_f(*this->base()); }
My m_f supplied to the template is ordinary enough; it returns a value.
Is your m_f a function object that uses result_of protocol to declare its return value?
It may be that while its operator() returns a value, its result<> is telling transform_iterator that it returns a reference.
For example, if its result<> looks like this:
template<typename> struct result; template
struct result { typedef T type; }; then transform iterator will deduce its return type to be a reference:
typedef typename ia_dflt_help< Reference , result_of
>::type reference; and it will use this as the return type of operator*. Hence the warning.
Instead, you need to declare result<> like this:
template<typename> struct result; template
struct result { typedef T type; }; (and possibly add a non-const reference version if necessary).
Regards, Nate.
Many thanks for the explanation.
Perhaps that should be added to
http://www.boost.org/doc/libs/1_47_0/libs/utility/utility.htm#result_of, or replace the
struct result

----------------------------------------
From: zeratul976@hotmail.com To: boost-users@lists.boost.org Subject: RE: [Boost-users] Odd Warning in transform_iterator.hpp ? Date: Thu, 28 Jul 2011 09:10:30 +0000
I'm using the current Boost library on Microsoft Visual Studio 2005. I'm getting a warning on line 121 of transform_iterator.hpp, complaining "returning address of local variable or temporary". The line in question is the body of this function:
typename super_t::reference dereference() const { return m_f(*this->base()); }
My m_f supplied to the template is ordinary enough; it returns a value.
Is your m_f a function object that uses result_of protocol to declare its return value?
It may be that while its operator() returns a value, its result<> is telling transform_iterator that it returns a reference.
For example, if its result<> looks like this:
template <typename> struct result; template
struct result { typedef T type; }; then transform iterator will deduce its return type to be a reference:
typedef typename ia_dflt_help< Reference , result_of
::type reference;
and it will use this as the return type of operator*. Hence the warning.
Let me elaborate a bit more...
I've run into this problem before. The reason this behaviour is surprising
is that if your operator() looks like this:
template <typename T>
T operator()(T o)
{
...
}
then you would think that this result<> template describes it's behaviour
accurately:
template <typename> struct result;
template
participants (2)
-
John M. Dlugosz
-
Nathan Ridge