id,summary,reporter,owner,description,type,status,milestone,component,version,severity,resolution,keywords,cc 9737,[spirit][classic] returning reference to temporary when using position_iterator with istreambuf_iterator,Julien Charbon ,Joel de Guzman,"In boost spirit classic, when using position_iterator with istreambuf_iterator, 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::reference and istreambuf_iterator::operator*() definition: * On clang3.4/libc++: istreambuf_iterator::reference type is 'char' and istreambuf_iterator::operator*() also returns a 'char'. * On gcc47/libstdc++ in c++11 mode: istreambuf_iterator::reference type is 'char' and istreambuf_iterator::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::reference type is 'char &' where istreambuf_iterator::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::reference is used. }}} Thus by default, iterator_adaptor::deference() from a position_iterator built of istreambuf_iterator returns a &char, which is fine only when istreambuf_iterator::reference type is also 'char &'.",Bugs,closed,To Be Determined,spirit,Boost 1.55.0,Problem,fixed,,