Subject: Re: [Boost-bugs] [Boost C++ Libraries] #8489: Unnecessary Definition of iterator_adaptor.hpp class Has Dangerous Return of Temporary Object
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-06-10 04:58:31
#8489: Unnecessary Definition of iterator_adaptor.hpp class Has Dangerous Return
of Temporary Object
-------------------------------------------+------------------------------
Reporter: Jeffrey D. Oldham <oldham@â¦> | Owner: jeffrey.hellrung
Type: Bugs | Status: new
Milestone: To Be Determined | Component: iterator
Version: Boost 1.53.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------------------+------------------------------
Comment (by dave):
The problem here is that the underlying iterator of the
{{{iterator_adaptor}}} is an {{{istreambuf_iterator<char>}}}, which quite
legitimately (for an input iterator) returns a non-reference type from its
{{{operator*}}}. This should be filed as a bug against Spirit.
To debug it, I applied this patch to iterator_adaptor.hpp, and ran the
failing program through stlfilt:
{{{
#!diff
--- iterator_adaptor.hpp 2013-06-09 20:32:52.000000000 -0700
+++
/Users/dave/src/boost/release/boost_1_53_0/boost/iterator/iterator_adaptor.hpp
2013-06-09 21:42:48.000000000 -0700
@@ -18,9 +18,11 @@
#include <boost/mpl/and.hpp>
#include <boost/mpl/not.hpp>
#include <boost/mpl/or.hpp>
+#include <boost/mpl/assert.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_convertible.hpp>
+#include <boost/type_traits/is_reference.hpp>
#ifdef BOOST_ITERATOR_REF_CONSTNESS_KILLS_WRITABILITY
# include <boost/type_traits/remove_reference.hpp>
@@ -303,7 +305,20 @@
// base_reference(), above, to get direct access to m_iterator.
//
typename super_t::reference dereference() const
- { return *m_iterator; }
+ {
+ BOOST_MPL_ASSERT((
+ mpl::or_<
+ mpl::not_<is_reference<typename super_t::reference> >
+ , is_reference<
+#ifdef BOOST_NO_CXX11_DECLTYPE
+ typename boost::iterator_reference<Base>::type
+#else
+ decltype(*m_iterator)
+#endif
+ >
+ >));
+ return *m_iterator;
+ }
template <
class OtherDerived, class OtherIterator, class V, class C, class R,
class D
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/8489#comment:7> 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:13 UTC