Fixed #9961: tests for hooks not derived frorm generic_hook

This commit is contained in:
Ion Gaztañaga
2014-05-01 10:21:40 +02:00
parent 09991acfb5
commit 9169db7f57
3 changed files with 93 additions and 78 deletions

View File

@@ -3800,6 +3800,7 @@ to be inserted in intrusive containers are allocated using `std::vector` or `std
* [@https://svn.boost.org/trac/boost/ticket/9746 #9746: Modern Sun CC compiler detects error in intrusive library header] * [@https://svn.boost.org/trac/boost/ticket/9746 #9746: Modern Sun CC compiler detects error in intrusive library header]
* [@https://svn.boost.org/trac/boost/ticket/9940 #9940: bad bug in intrusive list with safe_link (or auto_unlink) hooks] * [@https://svn.boost.org/trac/boost/ticket/9940 #9940: bad bug in intrusive list with safe_link (or auto_unlink) hooks]
* [@https://svn.boost.org/trac/boost/ticket/9949 #9949: clear header node hooks upon intrusive container destruction] * [@https://svn.boost.org/trac/boost/ticket/9949 #9949: clear header node hooks upon intrusive container destruction]
* [@https://svn.boost.org/trac/boost/ticket/9961 #9961: tests for hooks not derived frorm generic_hook]
* Optimized tree rebalancing code to avoid redundant assignments. * Optimized tree rebalancing code to avoid redundant assignments.

View File

@@ -318,6 +318,9 @@
<File <File
RelativePath="..\..\..\test\Jamfile.v2"> RelativePath="..\..\..\test\Jamfile.v2">
</File> </File>
<File
RelativePath="..\..\..\test\nonhook_node.hpp">
</File>
<File <File
RelativePath="..\..\..\test\smart_ptr.hpp"> RelativePath="..\..\..\test\smart_ptr.hpp">
</File> </File>

View File

@@ -1,16 +1,30 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Matei David 2014-2014.
// (C) Copyright Ion Gaztanaga 2014-2014.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_NONHOOK_NODE_HPP #ifndef BOOST_INTRUSIVE_DETAIL_NONHOOK_NODE_HPP
#define BOOST_INTRUSIVE_DETAIL_NONHOOK_NODE_HPP #define BOOST_INTRUSIVE_DETAIL_NONHOOK_NODE_HPP
#include <boost/intrusive/detail/config_begin.hpp> #include <boost/intrusive/detail/config_begin.hpp>
#include <boost/intrusive/list.hpp>
#include <boost/intrusive/pointer_traits.hpp> #include <boost/intrusive/pointer_traits.hpp>
#include <boost/intrusive/detail/utilities.hpp> #include <boost/intrusive/detail/utilities.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/static_assert.hpp>
namespace boost{ namespace boost{
namespace intrusive{ namespace intrusive{
//This node will only be used in safe or auto unlink modes
//so test it's been properly released
template < typename Node_Traits, template <typename> class Node_Algorithms > template < typename Node_Traits, template <typename> class Node_Algorithms >
struct nonhook_node_member : public Node_Traits::node struct nonhook_node_member : public Node_Traits::node
{ {
@@ -24,29 +38,23 @@ struct nonhook_node_member : public Node_Traits::node
{ {
node_algorithms::init(pointer_traits<node_ptr>::pointer_to(static_cast< node& >(*this))); node_algorithms::init(pointer_traits<node_ptr>::pointer_to(static_cast< node& >(*this)));
} }
nonhook_node_member(const nonhook_node_member& rhs) nonhook_node_member(const nonhook_node_member& rhs)
{ {
if (rhs.is_linked()) BOOST_TEST(!rhs.is_linked());
{
std::cerr << "nonhook_node_member copy ctor from linked: &=" << (void*)this << ", rhs=" << (void*)&rhs << std::endl;
}
*this = rhs; *this = rhs;
} }
nonhook_node_member& operator = (const nonhook_node_member& rhs) nonhook_node_member& operator = (const nonhook_node_member& rhs)
{ {
if (is_linked() or rhs.is_linked()) BOOST_TEST(!this->is_linked() && !rhs.is_linked());
{
std::cerr << "nonhook_node_member copy asop to/from linked: &=" << (void*)this << ", rhs=" << (void*)&rhs << std::endl;
}
static_cast< node& >(*this) = rhs; static_cast< node& >(*this) = rhs;
return *this; return *this;
} }
~nonhook_node_member() ~nonhook_node_member()
{ {
if (is_linked()) BOOST_TEST(!this->is_linked());
{
std::cerr << "nonhook_node_member dtor of linked: &=" << (void*)this << std::endl;
}
node_algorithms::init(pointer_traits<node_ptr>::pointer_to(static_cast< node& >(*this))); node_algorithms::init(pointer_traits<node_ptr>::pointer_to(static_cast< node& >(*this)));
} }
@@ -55,6 +63,7 @@ struct nonhook_node_member : public Node_Traits::node
node_algorithms::swap_nodes(pointer_traits<node_ptr>::pointer_to(static_cast< node& >(*this)), node_algorithms::swap_nodes(pointer_traits<node_ptr>::pointer_to(static_cast< node& >(*this)),
pointer_traits<node_ptr>::pointer_to(static_cast< node& >(other))); pointer_traits<node_ptr>::pointer_to(static_cast< node& >(other)));
} }
bool is_linked() const bool is_linked() const
{ {
return !node_algorithms::unique(pointer_traits<const_node_ptr>::pointer_to(static_cast< const node& >(*this))); return !node_algorithms::unique(pointer_traits<const_node_ptr>::pointer_to(static_cast< const node& >(*this)));
@@ -78,6 +87,8 @@ struct nonhook_node_member_value_traits
static const link_mode_type link_mode = Link_Mode; static const link_mode_type link_mode = Link_Mode;
BOOST_STATIC_ASSERT((Link_Mode == safe_link || Link_Mode == auto_unlink));
static node_ptr to_node_ptr(reference value) static node_ptr to_node_ptr(reference value)
{ {
return pointer_traits<node_ptr>::pointer_to(static_cast<node&>(value.*P)); return pointer_traits<node_ptr>::pointer_to(static_cast<node&>(value.*P));