|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r82521 - in trunk: boost/spirit/home/karma/detail libs/spirit/test libs/spirit/test/karma
From: hartmut.kaiser_at_[hidden]
Date: 2013-01-17 08:33:58
Author: hkaiser
Date: 2013-01-17 08:33:58 EST (Thu, 17 Jan 2013)
New Revision: 82521
URL: http://svn.boost.org/trac/boost/changeset/82521
Log:
Fix #7900: karma indirect_iterator returns reference to temporary
Added:
trunk/libs/spirit/test/karma/regression_iterator.cpp (contents, props changed)
Text files modified:
trunk/boost/spirit/home/karma/detail/indirect_iterator.hpp | 8 +++++---
trunk/libs/spirit/test/Jamfile | 1 +
2 files changed, 6 insertions(+), 3 deletions(-)
Modified: trunk/boost/spirit/home/karma/detail/indirect_iterator.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/detail/indirect_iterator.hpp (original)
+++ trunk/boost/spirit/home/karma/detail/indirect_iterator.hpp 2013-01-17 08:33:58 EST (Thu, 17 Jan 2013)
@@ -25,14 +25,16 @@
indirect_iterator<Iterator>
, typename boost::detail::iterator_traits<Iterator>::value_type
, boost::forward_traversal_tag
- , typename boost::detail::iterator_traits<Iterator>::value_type const&>
+ , typename boost::detail::iterator_traits<Iterator>::reference>
{
typedef typename boost::detail::iterator_traits<Iterator>::value_type
base_value_type;
+ typedef typename boost::detail::iterator_traits<Iterator>::reference
+ base_reference_type;
typedef boost::iterator_facade<
indirect_iterator<Iterator>, base_value_type
- , boost::forward_traversal_tag, base_value_type const&
+ , boost::forward_traversal_tag, base_reference_type
> base_type;
public:
@@ -56,7 +58,7 @@
return *iter_ == *other.iter_;
}
- typename base_type::reference dereference() const
+ base_reference_type dereference() const
{
return **iter_;
}
Modified: trunk/libs/spirit/test/Jamfile
==============================================================================
--- trunk/libs/spirit/test/Jamfile (original)
+++ trunk/libs/spirit/test/Jamfile 2013-01-17 08:33:58 EST (Thu, 17 Jan 2013)
@@ -253,6 +253,7 @@
[ run karma/regression_container_variant_sequence.cpp : : : : karma_regression_container_variant_sequence ]
[ run karma/regression_real_0.cpp : : : : karma_regression_real_0 ]
[ run karma/regression_unicode_char.cpp : : : : karma_regression_unicode_char ]
+ [ run karma/regression_iterator.cpp : : : : karma_regression_iterator ]
;
Added: trunk/libs/spirit/test/karma/regression_iterator.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/karma/regression_iterator.cpp 2013-01-17 08:33:58 EST (Thu, 17 Jan 2013)
@@ -0,0 +1,42 @@
+// Copyright (c) 2013 Louis Dionne
+// Copyright (c) 2001-2013 Hartmut Kaiser
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#include <boost/range/adaptor/transformed.hpp>
+#include <boost/spirit/include/karma.hpp>
+
+#include <iostream>
+
+// Note how the return is made by value instead of by reference.
+template <typename T> T identity(T const& t) { return t; }
+
+template <typename Char, typename Expr, typename CopyExpr, typename CopyAttr
+ , typename Delimiter, typename Attribute>
+bool test(Char const *expected,
+ boost::spirit::karma::detail::format_manip<
+ Expr, CopyExpr, CopyAttr, Delimiter, Attribute> const& fm)
+{
+ std::ostringstream ostrm;
+ ostrm << fm;
+ return ostrm.good() && ostrm.str() == expected;
+}
+
+int main()
+{
+ namespace karma = boost::spirit::karma;
+ namespace adaptors = boost::adaptors;
+ int ints[] = {0, 1, 2, 3, 4};
+
+ BOOST_TEST((test("0 1 2 3 4",
+ karma::format(karma::int_ % ' ',
+ ints | adaptors::transformed(&identity<int>)))
+ ));
+
+ return boost::report_errors();
+}
+
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk