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

Subject: Re: [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:10:41


#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
Resolution: | Keywords:
------------------------------------------+---------------------

Comment (by Julien Charbon <jcharbon@…>):

 Side-effects of this returning reference to temporary are enlighten with
 attached test case:

 * clang34/libc++ (fail):

 {{{
 $ 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; }
                  ^~~~~~~~~~~
 ...
 $ ./test-boost

 File: internal string
 Line: 1
 Col: 1
 Expecting a number, but found something else

 Parsing failed
 }}}

 * gcc47/libstdc++ in c++11 mode (fail):

 {{{
 $ g++47 -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]
 ...
 $ ./test-boost

 File: internal string
 Line: 1
 Col: 1
 Expecting a number, but found something else

 Parsing failed
 }}}

 * gcc47/libstdc++ default mode (success):

 {{{
 $ g++47 -O2 -Wall test-boost.cpp -o test-boost
 $ ./test-boost
 Parsing:
 0, 1, 2
 Parses OK:
 0: 0
 1: 1
 2: 2
 }}}

  For the record the complete warnings clang34/libc++:

 {{{
 $ clang++34 -O2 -Wall test-boost.cpp -o test-boost
 In file included from test-boost.cpp:5:
 In file included from
 source/boost/boost/spirit/include/classic_position_iterator.hpp:11:
 In file included from
 source/boost/boost/spirit/home/classic/iterator/position_iterator.hpp:98:
 In file included from
 source/boost/boost/spirit/home/classic/iterator/impl/position_iterator.ipp:15:
 In file included from source/boost/boost/iterator_adaptors.hpp:11:
 source/boost/boost/iterator/iterator_adaptor.hpp:310:18: warning:
 returning reference to local temporary object [-Wreturn-stack-address]
         { return *m_iterator; }
                  ^~~~~~~~~~~
 source/boost/boost/iterator/iterator_facade.hpp:514:20: note: in
 instantiation of member function
 'boost::iterator_adaptor<boost::spirit::classic::position_iterator<boost::spirit::classic::multi_pass<std::__1::istreambuf_iterator<char,
 std::__1::char_traits<char> >,
 boost::spirit::classic::multi_pass_policies::input_iterator,
 boost::spirit::classic::multi_pass_policies::ref_counted,
 boost::spirit::classic::multi_pass_policies::buf_id_check,
 boost::spirit::classic::multi_pass_policies::std_deque>,
 boost::spirit::classic::file_position_base<std::__1::basic_string<char> >,
 boost::spirit::classic::nil_t>,
 boost::spirit::classic::multi_pass<std::__1::istreambuf_iterator<char,
 std::__1::char_traits<char> >,
 boost::spirit::classic::multi_pass_policies::input_iterator,
 boost::spirit::classic::multi_pass_policies::ref_counted,
 boost::spirit::classic::multi_pass_policies::buf_id_check,
 boost::spirit::classic::multi_pass_policies::std_deque>, const char,
 boost::forward_traversal_tag, boost::use_default,
 boost::use_default>::dereference' requested here
           return f.dereference();
                    ^
 source/boost/boost/iterator/iterator_facade.hpp:639:40: note: in
 instantiation of function template specialization
 'boost::iterator_core_access::dereference<boost::spirit::classic::position_iterator<boost::spirit::classic::multi_pass<std::__1::istreambuf_iterator<char,
 std::__1::char_traits<char> >,
 boost::spirit::classic::multi_pass_policies::input_iterator,
 boost::spirit::classic::multi_pass_policies::ref_counted,
 boost::spirit::classic::multi_pass_policies::buf_id_check,
 boost::spirit::classic::multi_pass_policies::std_deque>,
 boost::spirit::classic::file_position_base<std::__1::basic_string<char> >,
 boost::spirit::classic::nil_t> >' requested here
           return iterator_core_access::dereference(this->derived());
                                        ^
 source/boost/boost/spirit/home/classic/core/scanner/scanner.hpp:54:20:
 note: in instantiation of member function
 'boost::iterator_facade<boost::spirit::classic::position_iterator<boost::spirit::classic::multi_pass<std::__1::istreambuf_iterator<char,
 std::__1::char_traits<char> >,
 boost::spirit::classic::multi_pass_policies::input_iterator,
 boost::spirit::classic::multi_pass_policies::ref_counted,
 boost::spirit::classic::multi_pass_policies::buf_id_check,
 boost::spirit::classic::multi_pass_policies::std_deque>,
 boost::spirit::classic::file_position_base<std::__1::basic_string<char> >,
 boost::spirit::classic::nil_t>, const char, boost::forward_traversal_tag,
 const char &, long long>::operator*' requested here
             return *scan.first;
                    ^
 source/boost/boost/spirit/home/classic/core/scanner/skipper.hpp:61:66:
 note: in instantiation of function template specialization
 'boost::spirit::classic::iteration_policy::get<boost::spirit::classic::scanner<boost::spirit::classic::position_iterator<boost::spirit::classic::multi_pass<std::__1::istreambuf_iterator<char,
 std::__1::char_traits<char> >,
 boost::spirit::classic::multi_pass_policies::input_iterator,
 boost::spirit::classic::multi_pass_policies::ref_counted,
 boost::spirit::classic::multi_pass_policies::buf_id_check,
 boost::spirit::classic::multi_pass_policies::std_deque>,
 boost::spirit::classic::file_position_base<std::__1::basic_string<char> >,
 boost::spirit::classic::nil_t>,
 boost::spirit::classic::scanner_policies<boost::spirit::classic::skipper_iteration_policy<boost::spirit::classic::iteration_policy>,
 boost::spirit::classic::match_policy,
 boost::spirit::classic::action_policy> > >' requested here
             while (!BaseT::at_end(scan) &&
 impl::isspace_(BaseT::get(scan)))
                                                                  ^
 source/boost/boost/spirit/home/classic/core/scanner/skipper.hpp:53:18:
 note: in instantiation of function template specialization
 'boost::spirit::classic::skipper_iteration_policy<boost::spirit::classic::iteration_policy>::skip<boost::spirit::classic::scanner<boost::spirit::classic::position_iterator<boost::spirit::classic::multi_pass<std::__1::istreambuf_iterator<char,
 std::__1::char_traits<char> >,
 boost::spirit::classic::multi_pass_policies::input_iterator,
 boost::spirit::classic::multi_pass_policies::ref_counted,
 boost::spirit::classic::multi_pass_policies::buf_id_check,
 boost::spirit::classic::multi_pass_policies::std_deque>,
 boost::spirit::classic::file_position_base<std::__1::basic_string<char> >,
 boost::spirit::classic::nil_t>,
 boost::spirit::classic::scanner_policies<boost::spirit::classic::skipper_iteration_policy<boost::spirit::classic::iteration_policy>,
 boost::spirit::classic::match_policy,
 boost::spirit::classic::action_policy> > >' requested here
             scan.skip(scan);
                  ^
 source/boost/boost/spirit/home/classic/core/scanner/scanner.hpp:252:43:
 note: in instantiation of function template specialization
 'boost::spirit::classic::skipper_iteration_policy<boost::spirit::classic::iteration_policy>::at_end<boost::spirit::classic::scanner<boost::spirit::classic::position_iterator<boost::spirit::classic::multi_pass<std::__1::istreambuf_iterator<char,
 std::__1::char_traits<char> >,
 boost::spirit::classic::multi_pass_policies::input_iterator,
 boost::spirit::classic::multi_pass_policies::ref_counted,
 boost::spirit::classic::multi_pass_policies::buf_id_check,
 boost::spirit::classic::multi_pass_policies::std_deque>,
 boost::spirit::classic::file_position_base<std::__1::basic_string<char> >,
 boost::spirit::classic::nil_t>,
 boost::spirit::classic::scanner_policies<boost::spirit::classic::skipper_iteration_policy<boost::spirit::classic::iteration_policy>,
 boost::spirit::classic::match_policy,
 boost::spirit::classic::action_policy> > >' requested here
             return iteration_policy_type::at_end(*this);
                                           ^
 source/boost/boost/spirit/home/classic/core/scanner/scanner.hpp:235:13:
 note: in instantiation of member function
 'boost::spirit::classic::scanner<boost::spirit::classic::position_iterator<boost::spirit::classic::multi_pass<std::__1::istreambuf_iterator<char,
 std::__1::char_traits<char> >,
 boost::spirit::classic::multi_pass_policies::input_iterator,
 boost::spirit::classic::multi_pass_policies::ref_counted,
 boost::spirit::classic::multi_pass_policies::buf_id_check,
 boost::spirit::classic::multi_pass_policies::std_deque>,
 boost::spirit::classic::file_position_base<std::__1::basic_string<char> >,
 boost::spirit::classic::nil_t>,
 boost::spirit::classic::scanner_policies<boost::spirit::classic::skipper_iteration_policy<boost::spirit::classic::iteration_policy>,
 boost::spirit::classic::match_policy,
 boost::spirit::classic::action_policy> >::at_end' requested here
             at_end();
             ^
 source/boost/boost/spirit/home/classic/core/scanner/impl/skipper.ipp:132:27:
 note: in instantiation of member function
 'boost::spirit::classic::scanner<boost::spirit::classic::position_iterator<boost::spirit::classic::multi_pass<std::__1::istreambuf_iterator<char,
 std::__1::char_traits<char> >,
 boost::spirit::classic::multi_pass_policies::input_iterator,
 boost::spirit::classic::multi_pass_policies::ref_counted,
 boost::spirit::classic::multi_pass_policies::buf_id_check,
 boost::spirit::classic::multi_pass_policies::std_deque>,
 boost::spirit::classic::file_position_base<std::__1::basic_string<char> >,
 boost::spirit::classic::nil_t>,
 boost::spirit::classic::scanner_policies<boost::spirit::classic::skipper_iteration_policy<boost::spirit::classic::iteration_policy>,
 boost::spirit::classic::match_policy,
 boost::spirit::classic::action_policy> >::scanner' requested here
                 scanner_t scan(first, last);
                           ^
 source/boost/boost/spirit/home/classic/core/scanner/impl/skipper.ipp:155:13:
 note: in instantiation of function template specialization
 'boost::spirit::classic::impl::phrase_parser<boost::spirit::classic::space_parser>::parse<boost::spirit::classic::position_iterator<boost::spirit::classic::multi_pass<std::__1::istreambuf_iterator<char,
 std::__1::char_traits<char> >,
 boost::spirit::classic::multi_pass_policies::input_iterator,
 boost::spirit::classic::multi_pass_policies::ref_counted,
 boost::spirit::classic::multi_pass_policies::buf_id_check,
 boost::spirit::classic::multi_pass_policies::std_deque>,
 boost::spirit::classic::file_position_base<std::__1::basic_string<char> >,
 boost::spirit::classic::nil_t>,
 boost::spirit::classic::sequence<boost::spirit::classic::alternative<boost::spirit::classic::action<boost::spirit::classic::real_parser<double,
 boost::spirit::classic::real_parser_policies<double> >,
 boost::spirit::classic::ref_value_actor<std::__1::vector<double,
 std::__1::allocator<double> >, boost::spirit::classic::push_back_action>
>, boost::spirit::classic::functor_parser<error_report_parser> >,
 boost::spirit::classic::kleene_star<boost::spirit::classic::sequence<boost::spirit::classic::alternative<boost::spirit::classic::chlit<char>,
 boost::spirit::classic::functor_parser<error_report_parser> >,
 boost::spirit::classic::alternative<boost::spirit::classic::action<boost::spirit::classic::real_parser<double,
 boost::spirit::classic::real_parser_policies<double> >,
 boost::spirit::classic::ref_value_actor<std::__1::vector<double,
 std::__1::allocator<double> >, boost::spirit::classic::push_back_action>
>, boost::spirit::classic::functor_parser<error_report_parser> > > > > >'
 requested here
             parse(first, last, p.derived(), skip.derived());
             ^
 test-boost.cpp:92:12: note: in instantiation of function template
 specialization
 'boost::spirit::classic::parse<boost::spirit::classic::position_iterator<boost::spirit::classic::multi_pass<std::__1::istreambuf_iterator<char,
 std::__1::char_traits<char> >,
 boost::spirit::classic::multi_pass_policies::input_iterator,
 boost::spirit::classic::multi_pass_policies::ref_counted,
 boost::spirit::classic::multi_pass_policies::buf_id_check,
 boost::spirit::classic::multi_pass_policies::std_deque>,
 boost::spirit::classic::file_position_base<std::__1::basic_string<char> >,
 boost::spirit::classic::nil_t>,
 boost::spirit::classic::sequence<boost::spirit::classic::alternative<boost::spirit::classic::action<boost::spirit::classic::real_parser<double,
 boost::spirit::classic::real_parser_policies<double> >,
 boost::spirit::classic::ref_value_actor<std::__1::vector<double,
 std::__1::allocator<double> >, boost::spirit::classic::push_back_action>
>, boost::spirit::classic::functor_parser<error_report_parser> >,
 boost::spirit::classic::kleene_star<boost::spirit::classic::sequence<boost::spirit::classic::alternative<boost::spirit::classic::chlit<char>,
 boost::spirit::classic::functor_parser<error_report_parser> >,
 boost::spirit::classic::alternative<boost::spirit::classic::action<boost::spirit::classic::real_parser<double,
 boost::spirit::classic::real_parser_policies<double> >,
 boost::spirit::classic::ref_value_actor<std::__1::vector<double,
 std::__1::allocator<double> >, boost::spirit::classic::push_back_action>
>, boost::spirit::classic::functor_parser<error_report_parser> > > > >,
 boost::spirit::classic::space_parser>' requested here
     return parse(pos_begin, pos_end,
            ^
 1 warning generated.
 }}}

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