Opened 10 years ago

Closed 10 years ago

#7900 closed Patches (fixed)

karma indirect_iterator returns reference to temporary

Reported by: Louis Dionne <louis.dionne92@…> Owned by: Hartmut Kaiser
Milestone: To Be Determined Component: spirit
Version: Boost Release Branch Severity: Problem
Keywords: karma indirect_iterator Cc:

Description

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@82516

Best,

Louis Dionne

Attachments (2)

indirect_iterator.diff (1.3 KB ) - added by Louis Dionne <louis.dionne92@…> 10 years ago.
fix for the issue
main.cpp (575 bytes ) - added by Louis Dionne <louis.dionne92@…> 10 years ago.
minimal code to reproduce the issue

Download all attachments as: .zip

Change History (5)

by Louis Dionne <louis.dionne92@…>, 10 years ago

Attachment: indirect_iterator.diff added

fix for the issue

by Louis Dionne <louis.dionne92@…>, 10 years ago

Attachment: main.cpp added

minimal code to reproduce the issue

comment:1 by Louis Dionne <louis.dionne92@…>, 10 years ago

Sorry for the mis-formatting of my setup. Should've previewed the ticket before posting!

My setup:

gcc version 4.7.2

clang version 3.2

boost-trunk@82516

comment:2 by Joel de Guzman, 10 years ago

Owner: changed from Joel de Guzman to Hartmut Kaiser

comment:3 by Hartmut Kaiser, 10 years ago

Resolution: fixed
Status: newclosed

(In [82521]) Fix #7900: karma indirect_iterator returns reference to temporary

Note: See TracTickets for help on using tickets.