|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r85315 - in trunk: boost/variant libs/variant/test
From: antoshkka_at_[hidden]
Date: 2013-08-12 08:00:13
Author: apolukhin
Date: 2013-08-12 08:00:13 EDT (Mon, 12 Aug 2013)
New Revision: 85315
URL: http://svn.boost.org/trac/boost/changeset/85315
Log:
Fix issue with const rvalue references in Boost.Variant (refs #8988)
Text files modified:
trunk/boost/variant/variant.hpp | 6 ++++--
trunk/libs/variant/test/rvalue_test.cpp | 26 ++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 2 deletions(-)
Modified: trunk/boost/variant/variant.hpp
==============================================================================
--- trunk/boost/variant/variant.hpp Mon Aug 12 07:58:17 2013 (r85314)
+++ trunk/boost/variant/variant.hpp 2013-08-12 08:00:13 EDT (Mon, 12 Aug 2013) (r85315)
@@ -1776,7 +1776,8 @@
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
template <class T>
- variant(T&& operand, typename boost::enable_if<boost::is_rvalue_reference<T&&> >::type* = 0)
+ variant(T&& operand, typename boost::enable_if<boost::is_rvalue_reference<T&&> >::type* = 0,
+ typename boost::disable_if<boost::is_const<T> >::type* = 0)
{
convert_construct( detail::variant::move(operand), 1L);
}
@@ -2187,7 +2188,8 @@
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
template <class T>
- typename boost::enable_if<boost::is_rvalue_reference<T&&>, variant& >::type operator=(T&& rhs)
+ typename boost::enable_if_c<boost::is_rvalue_reference<T&&>::value && !boost::is_const<T>::value, variant& >::type
+ operator=(T&& rhs)
{
move_assign( detail::variant::move(rhs) );
return *this;
Modified: trunk/libs/variant/test/rvalue_test.cpp
==============================================================================
--- trunk/libs/variant/test/rvalue_test.cpp Mon Aug 12 07:58:17 2013 (r85314)
+++ trunk/libs/variant/test/rvalue_test.cpp 2013-08-12 08:00:13 EDT (Mon, 12 Aug 2013) (r85315)
@@ -82,6 +82,13 @@
BOOST_CHECK(true);
}
+
+void run_const_rvalues()
+{
+ BOOST_CHECK(true);
+}
+
+
#else
@@ -211,6 +218,24 @@
#endif
}
+inline const std::string get_string() { return "test"; }
+inline const boost::variant<int, std::string> get_variant() { return std::string("test"); }
+inline const boost::variant<std::string, int> get_variant2() { return std::string("test"); }
+
+void run_const_rvalues()
+{
+ typedef boost::variant<int, std::string> variant_t;
+ const variant_t v1(get_string());
+ const variant_t v2(get_variant());
+ const variant_t v3(get_variant2());
+
+ variant_t v4, v5, v6, v7;
+ v4 = get_string();
+ v5 = get_variant();
+ v6 = get_variant2();
+ v7 = boost::move(v1);
+}
+
#endif
struct nothrow_copyable_throw_movable {
@@ -238,5 +263,6 @@
run_move_only();
run_moves_are_noexcept();
run_tricky_compilation_test();
+ run_const_rvalues();
return 0;
}
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