diff --git a/include/boost/smart_ptr/enable_shared_from.hpp b/include/boost/smart_ptr/enable_shared_from.hpp index db347e6..be88b30 100644 --- a/include/boost/smart_ptr/enable_shared_from.hpp +++ b/include/boost/smart_ptr/enable_shared_from.hpp @@ -3,7 +3,7 @@ // enable_shared_from.hpp // -// Copyright 2019 Peter Dimov +// Copyright 2019, 2020 Peter Dimov // // Distributed under the Boost Software License, Version 1.0. // See accompanying file LICENSE_1_0.txt or copy at @@ -19,17 +19,21 @@ namespace boost class enable_shared_from: public enable_shared_from_this { +private: + + using enable_shared_from_this::shared_from_this; + using enable_shared_from_this::weak_from_this; }; template shared_ptr shared_from( T * p ) { - return shared_ptr( p->enable_shared_from::shared_from_this(), p ); + return shared_ptr( p->enable_shared_from_this::shared_from_this(), p ); } template weak_ptr weak_from( T * p ) BOOST_SP_NOEXCEPT { - return weak_ptr( p->enable_shared_from::weak_from_this(), p ); + return weak_ptr( p->enable_shared_from_this::weak_from_this(), p ); } } // namespace boost diff --git a/test/Jamfile b/test/Jamfile index 8e121b8..c62fd0b 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -356,3 +356,6 @@ run allocate_unique_value_test.cpp ; run sp_guides_test.cpp ; run sp_guides_test2.cpp ; run wp_guides_test.cpp ; + +compile-fail shared_from_fail.cpp ; +compile-fail weak_from_fail.cpp ; diff --git a/test/shared_from_fail.cpp b/test/shared_from_fail.cpp new file mode 100644 index 0000000..b7275a7 --- /dev/null +++ b/test/shared_from_fail.cpp @@ -0,0 +1,16 @@ +// Copyright 2020 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include + +struct X: public boost::enable_shared_from +{ +}; + +int main() +{ + boost::shared_ptr px( new X ); + px->shared_from_this(); +} diff --git a/test/weak_from_fail.cpp b/test/weak_from_fail.cpp new file mode 100644 index 0000000..5d75e40 --- /dev/null +++ b/test/weak_from_fail.cpp @@ -0,0 +1,16 @@ +// Copyright 2020 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include + +struct X: public boost::enable_shared_from +{ +}; + +int main() +{ + boost::shared_ptr px( new X ); + px->weak_from_this(); +}