|
Boost : |
Subject: Re: [boost] [Multiarray] & [Range] MSVC/gcc warning: returning address of local variable or temporary
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2008-11-12 04:34:20
David Abrahams skrev:
> 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.
Do you mean that I can detect the return type of operator[] at
compile-time and do correct forwarding? If so, how?
-Thorsten
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk