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:
committed by
Avi Kivity
parent
8efcec1949
commit
cf42e4c1a4
@@ -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>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user