[Boost-bugs] [Boost C++ Libraries] #9737: [spirit][classic] returning reference to temporary when using position_iterator with istreambuf_iterator<char>

Subject: [Boost-bugs] [Boost C++ Libraries] #9737: [spirit][classic] returning reference to temporary when using position_iterator with istreambuf_iterator<char>
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-03-04 14:01:10


#9737: [spirit][classic] returning reference to temporary when using
position_iterator with istreambuf_iterator<char>
-----------------------------------------+---------------------
 Reporter: Julien Charbon <jcharbon@…> | Owner: djowel
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: spirit
  Version: Boost 1.55.0 | Severity: Problem
 Keywords: |
-----------------------------------------+---------------------
 In boost spirit classic, when using position_iterator with
 istreambuf_iterator<char>, the underlying iterator_adaptor::deference()
 might return a reference to temporary:

 For example with clang34/libc++:

 {{{
 $ clang++34 -O2 -Wall test-boost.cpp -o test-boost
 source/boost/boost/iterator/iterator_adaptor.hpp:310:18: warning:
 returning reference to local temporary object [-Wreturn-stack-address]
         { return *m_iterator; }
                  ^~~~~~~~~~~
 }}}

 or with gcc47/libstdc++ in c++11 mode:

 {{{
 $ g++47 --std=c++11 -O2 -Wall test-boost.cpp -o test-boost
 source/boost/boost/iterator/iterator_adaptor.hpp:310:19: warning:
 returning reference to temporary [enabled by default]
 }}}

 but not in default gcc47 default code (gnu++98):

 {{{
 $ g++47 -O2 -Wall test-boost.cpp -o test-boost
 }}}

 We tracked down this issue to istreambuf_iterator<char>::reference and
 istreambuf_iterator<char>::operator*() definition:

 * On clang3.4/libc++:

 istreambuf_iterator<char>::reference type is 'char' and
 istreambuf_iterator<char>::operator*() also returns a 'char'.

 * On gcc47/libstdc++ in c++11 mode:

 istreambuf_iterator<char>::reference type is 'char' and
 istreambuf_iterator<char>::operator*() also returns a 'char'.

 See: istreambuf_iterator::reference changes from _CharT& to _CharT:
 http://gcc.gnu.org/wiki/Cxx11AbiCompatibility

 * However on gcc47/libstdc++ in default mode:

 istreambuf_iterator<char>::reference type is 'char &' where
 istreambuf_iterator<char>::operator*() returns a 'char'.

  And position_iterator being built from iterator_adaptor with:

 {{{
     typedef boost::iterator_adaptor<
         main_iter_t,
         ForwardIterT,
         const_value_type,
         boost::forward_traversal_tag
> type;
 }}}

  there is no 5th template type which defines iterator_adaptor 'Reference':

 {{{
   // Iterator Adaptor
   // ...
   //
   // Reference - the reference type of the resulting iterator, and in
   // particular, the result type of operator*(). If not supplied but
   // Value is supplied, Value& is used. Otherwise
   // iterator_traits<Base>::reference is used.
 }}}

  Thus by default, iterator_adaptor::deference() from a position_iterator
 built of istreambuf_iterator<char> returns a &char, which is fine only
 when istreambuf_iterator<char>::reference type is also 'char &'.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/9737>
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:15 UTC