[Boost-bugs] [Boost C++ Libraries] #7900: karma indirect_iterator returns reference to temporary

Subject: [Boost-bugs] [Boost C++ Libraries] #7900: karma indirect_iterator returns reference to temporary
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-01-17 07:04:42


#7900: karma indirect_iterator returns reference to temporary
-----------------------------------------------------+----------------------
 Reporter: Louis Dionne <louis.dionne92@…> | Owner: djowel
     Type: Patches | Status: new
Milestone: To Be Determined | Component: spirit
  Version: Boost Release Branch | Severity: Problem
 Keywords: karma indirect_iterator |
-----------------------------------------------------+----------------------
 Hello,

 The indirect_iterator in
 boost/spirit/home/karma/detail/indirect_iterator.hpp
 returns a reference to a temporary in at least one corner case. The
 compiler
 will issue a warning, but it's still UB.

 I attached the minimal code to reproduce the behavior as well as a fix.
 Without the fix, it will print crap and issue a warning (on Clang and
 GCC).

 What happens:
 I create a transformed_range, which uses a transform_iterator under the
 hood.
 Since the function performing the transformation returns by value, the
 the iterator_traits<transform_iterator>::reference type is NOT the same as
 iterator_traits<transform_iterator>::value_type const&, hence the return
 of a
 reference to a temporary.

 My setup:
     gcc version 4.7.2
     clang version 3.2
     boost-trunk_at_82516

 Best,

 Louis Dionne

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