Boost logo

Boost :

Subject: Re: [boost] [Multiarray] & [Range] MSVC/gcc warning: returning address of local variable or temporary
From: David Abrahams (dave_at_[hidden])
Date: 2008-11-11 23:44:56


on Tue Nov 11 2008, Steven Watanabe <watanabesj-AT-gmail.com> wrote:

> AMDG
>
> John Reid wrote:
>> The following code generates a worrying warning under MSVC:
>>
>> <snip>
>>
>> I'm using msvc 8.0 express and boost 1.37.0 release. I've seen similar warnings from
>> gcc 4.3 on similar code. Is this a problem with boost.Multiarray, boost.range or the
>> compiler? My guess is that Multiarray has defined its iterators incorrectly. Can
>> anyone confirm this/provide a fix?
>
> This is the result of a bad interaction between
> iterator_range and iterator_facade.
>
> iterator_facade makes the result of operator[] an rvalue
> http://www.boost.org/libs/iterator/doc/iterator_facade.html#operator
>
> iterator_range assumes that operator[] for an iterator
> returns the type reference.
> http://www.boost.org/libs/range/doc/utility_class.html#iter_range

FWIW, iterator_range is in the wrong here. That is not a safe
assumption. It can, however, be checked for fairly reliably at
compile-time.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk