core: Fix enable_lw_shared_from_this<T>::shared_from_this() const

Compilation failed when shared_from_this() was called on a const object.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
This commit is contained in:
Tomasz Grabiec
2015-06-16 19:28:24 +02:00
committed by Avi Kivity
parent 8efcec1949
commit cf42e4c1a4
2 changed files with 12 additions and 1 deletions

View File

@@ -291,7 +291,7 @@ template <typename T>
inline
lw_shared_ptr<const T>
enable_lw_shared_from_this<T>::shared_from_this() const {
return lw_shared_ptr<const T>(this);
return lw_shared_ptr<const T>(const_cast<enable_lw_shared_from_this*>(this));
}
template <typename T>

View File

@@ -82,3 +82,14 @@ BOOST_AUTO_TEST_CASE(test_lw_const_ptr_2) {
lw_shared_ptr<const E> pe3 = pe2;
BOOST_REQUIRE(pe2 == pe3);
}
struct F : enable_lw_shared_from_this<F> {
auto const_method() const {
return shared_from_this();
}
};
BOOST_AUTO_TEST_CASE(test_shared_from_this_called_on_const_object) {
auto ptr = make_lw_shared<F>();
ptr->const_method();
}