[Bug libstdc++/38719] New: _Fwd_list_iterator::_M_next() returns reference to local memory

rguenth at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Sun Jan 4 12:47:00 GMT 2009


const _Self&
      _M_next() const
      {
        if (_M_node)
          return _Fwd_list_iterator(this->_M_node->_M_next);
        else
          return _Fwd_list_iterator(0);
      }

returns a reference to a _Fwd_list_iterator object that is constructed on the
_M_next() stack frame.  This causes (at least)
23_containers/forward_list/operations/1.cc to fail on the alias-improvements
branch.

The same is true for _Fwd_list_const_iterator (and maybe other parts of the
standard library).

Fixing it to return by value fixes the failure, code quality should be
unchanged - the calls now use return slot optmization (thus the object
is constructed on the caller stack instead, which is valid).


-- 
           Summary: _Fwd_list_iterator::_M_next() returns reference to local
                    memory
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: critical
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rguenth at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38719



More information about the Gcc-bugs mailing list