Subject: [Boost-bugs] [Boost C++ Libraries] #12081: the minmax creates dangling references too easily
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-03-20 20:23:47
#12081: the minmax creates dangling references too easily
------------------------------+----------------------
Reporter: anonymous | Owner: marshall
Type: Bugs | Status: new
Milestone: To Be Determined | Component: minmax
Version: Boost 1.60.0 | Severity: Problem
Keywords: |
------------------------------+----------------------
First.
minmax's example codes has created dangling references.
{{{
boost::tuple<int const&, int const&> result1 = boost::minmax(1, 0);
//actual code
boost::tuple<int, int> result1 = boost::minmax(1, 0); //expected code
}}}
http://www.boost.org/doc/libs/1_60_0/libs/algorithm/minmax/index.html
[[BR]]
http://www.boost.org/doc/libs/1_60_0/libs/algorithm/minmax/example/minmax_ex.cpp
[[BR]]
Second.
The design of minmax is unsuitable for that of C++11 era.
Consider the following.
{{{
auto tp = minmax(1,2);
tp.get<0>(); // Undefined behavior
}}}
This code looks like fairy normal, but it causes undefined behavior. Since
the minmax returns tuple<T const&, T const&>, the 'auto tp' has dangling
references. [[BR]]
I think we should change the return type from tuple<T const&, T const&> to
tuple<T,T>.
See also: https://groups.google.com/a/isocpp.org/forum/#!topic/std-
discussion/HLiJJBRNYSw
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/12081> 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:19 UTC