[Boost-bugs] [Boost C++ Libraries] #10493: Since 1.56, any_range with non-reference references can cause UB

Subject: [Boost-bugs] [Boost C++ Libraries] #10493: Since 1.56, any_range with non-reference references can cause UB
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-09-11 14:04:19


#10493: Since 1.56, any_range with non-reference references can cause UB
------------------------------+------------------------
 Reporter: nofitserov@… | Owner: neilgroves
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: range
  Version: Boost 1.56.0 | Severity: Regression
 Keywords: |
------------------------------+------------------------
 This must be related to #10360. This is a regression since 1.55.

 When using any_range<T, category, T, ptrdiff_t>, mutable dereference()
 method returns mutable_reference_type_generator<T>::type, which becomes
 T&. So dereference() returns a dangling reference to an on-the-fly
 computed value.

 See attached test case, which works with 1.55, and fails with
 -fsanitize=address on Clang 3.5 with 1.56.

 {{{
 #include <boost/range/any_range.hpp>
 #include <boost/range/adaptor/transformed.hpp>
 #include <cmath>
 #include <iostream>

 typedef boost::any_range<
     std::string,
     boost::forward_traversal_tag,
     std::string,
     std::ptrdiff_t
> range_t;

 std::string f(std::string a)
 {
     return a + "!";
 }

 int main()
 {
     std::vector<std::string> v = {"a", "b"};
     range_t r = v | boost::adaptors::transformed(f);
     for (auto&& a : r)
         std::cout << a << std::endl;
     return 0;
 }

 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/10493>
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:16 UTC