#include <set>

class test_unit;

void deregister_test_unit( test_unit* tu );

class test_unit {
public:
    ~test_unit() { deregister_test_unit(this); }
//  virtual ~test_unit() { deregister_test_unit(this); } // <- this line fixes the problem
};

class test_case : public test_unit {
};

class Framework {
public:
    typedef std::set<test_unit*> test_unit_store;
    Framework()
    {
        register_test_unit(new test_case);
    }

    ~Framework()
    {
        clear();
    }

    void register_test_unit( test_case* tc )
    {
        m_test_units.insert( tc );
    }

    void clear()
    {
        while( !m_test_units.empty() ) 
        {
            test_unit_store::value_type const& tu = *m_test_units.begin();
/* these two lines also fix the problem
            test_case const* tc=(test_case const*)tu;
            delete tc;
*/
            delete (test_case const*)tu;
        }
    }

    test_unit_store m_test_units;
};

static Framework framework;

void deregister_test_unit( test_unit* tu )
{
    framework.m_test_units.erase( tu );
}

int main()
{
    return 0;
}

