From 2d5c7f3be70e6e438df7dca64f8876a5a5ede7ee Mon Sep 17 00:00:00 2001
From: Antony Polukhin <antoshkka@gmail.com>
Date: Tue, 3 Dec 2013 16:42:25 +0400
Subject: [PATCH] Fix issue #9462 with returning rvalue reference instead of
returning by copy
---
doc/any.xml | 14 +++++++++++++-
include/boost/any.hpp | 17 +++--------------
2 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/doc/any.xml b/doc/any.xml
index 0f2f9ac..92944cc 100644
|
a
|
b
|
public:
|
| 499 | 499 | <paramtype><classname>any</classname> &</paramtype> |
| 500 | 500 | </parameter> |
| 501 | 501 | </signature> |
| 502 | | |
| | 502 | |
| | 503 | <signature> |
| | 504 | <template> |
| | 505 | <template-type-parameter name="T"/> |
| | 506 | </template> |
| | 507 | |
| | 508 | <type>T</type> |
| | 509 | |
| | 510 | <parameter name="operand"> |
| | 511 | <paramtype><classname>any</classname> &&</paramtype> |
| | 512 | </parameter> |
| | 513 | </signature> |
| | 514 | |
| 503 | 515 | <signature> |
| 504 | 516 | <template> |
| 505 | 517 | <template-type-parameter name="T"/> |
diff --git a/include/boost/any.hpp b/include/boost/any.hpp
index 44cfd0a..3798952 100644
|
a
|
b
|
|
| 40 | 40 | #include <cstring> |
| 41 | 41 | # endif |
| 42 | 42 | |
| 43 | | #if defined(_MSC_VER) |
| 44 | | #pragma warning(push) |
| 45 | | #pragma warning(disable: 4172) // Mistakenly warns: returning address of local variable or temporary |
| 46 | | #endif |
| 47 | | |
| 48 | 43 | namespace boost |
| 49 | 44 | { |
| 50 | 45 | class any |
| … |
… |
namespace boost
|
| 293 | 288 | inline ValueType any_cast(const any & operand) |
| 294 | 289 | { |
| 295 | 290 | typedef BOOST_DEDUCED_TYPENAME remove_reference<ValueType>::type nonref; |
| 296 | | |
| 297 | | |
| 298 | 291 | return any_cast<const nonref &>(const_cast<any &>(operand)); |
| 299 | 292 | } |
| 300 | 293 | |
| 301 | 294 | #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES |
| 302 | 295 | template<typename ValueType> |
| 303 | | inline ValueType&& any_cast(any&& operand) |
| | 296 | inline ValueType any_cast(any&& operand) |
| 304 | 297 | { |
| 305 | 298 | BOOST_STATIC_ASSERT_MSG( |
| 306 | | boost::is_rvalue_reference<ValueType&&>::value |
| | 299 | boost::is_rvalue_reference<ValueType&&>::value /*true if ValueType is rvalue or just a value*/ |
| 307 | 300 | || boost::is_const< typename boost::remove_reference<ValueType>::type >::value, |
| 308 | 301 | "boost::any_cast shall not be used for getting nonconst references to temporary objects" |
| 309 | 302 | ); |
| 310 | | return any_cast<ValueType&&>(operand); |
| | 303 | return any_cast<ValueType>(operand); |
| 311 | 304 | } |
| 312 | 305 | #endif |
| 313 | 306 | |
| … |
… |
namespace boost
|
| 336 | 329 | // accompanying file LICENSE_1_0.txt or copy at |
| 337 | 330 | // http://www.boost.org/LICENSE_1_0.txt) |
| 338 | 331 | |
| 339 | | #if defined(_MSC_VER) |
| 340 | | #pragma warning(pop) |
| 341 | | #endif |
| 342 | | |
| 343 | 332 | #endif |