Subject: [Boost-bugs] [Boost C++ Libraries] #13137: boost::optional::operator*() doesn't have "const &&" overload, allowing incorrect usage
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-07-26 06:00:30
#13137: boost::optional::operator*() doesn't have "const &&" overload, allowing
incorrect usage
--------------------------------+-------------------------------
Reporter: for.gcc.bugzilla@⦠| Owner: Fernando Cacciola
Type: Bugs | Status: new
Milestone: To Be Determined | Component: optional
Version: Boost 1.65.0 | Severity: Problem
Keywords: |
--------------------------------+-------------------------------
{{{
#include <boost/optional.hpp>
const boost::optional<int> f()
{
return {1};
}
int main()
{
const int& ref = *f();
// creates a boost::optional temporary
// "*tmp" binds to "optional::operator*() const&"
// "ref" starts pointing to internals of the returned temporary
// temporary gets destroyed
// we have a dangling reference
}
}}}
at the same time, std::optional in C++17 does have
{{{
constexpr const T&& operator*() const &&;
}}}
[http://en.cppreference.com/w/cpp/utility/optional/operator* overload],
which lets the code above work correctly.
-- Ticket URL: <https://svn.boost.org/trac10/boost/ticket/13137> 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-07-26 06:03:40 UTC