nkzxw / ontl

Automatically exported from code.google.com/p/ontl
0 stars 0 forks source link

stl::shared_ptr doesn't work #24

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

long test_shared_ptr() {
    class tester {
    public:
        static int &instance_count() {
            static int i = 0;
            return i;
        }
        tester() {
            ++instance_count();
        }
        ~tester() {
            --instance_count();
        }
    };

    typedef std::shared_ptr<tester> tester_ptr;

    {
        tester_ptr  test1( new tester() );

        if( tester::instance_count() != 1 ) {
            return 1;
        }

        tester_ptr  test2( test1 );

        if( tester::instance_count() != 1 ) {
            return 2;
        }

        tester_ptr  test3;
        //test3 = test2;

        if( tester::instance_count() != 1 ) {
            return 3;
        }

        //test2 = test3;

        if( tester::instance_count() != 1 ) {
            return 4;
        }
    }
    if( tester::instance_count() != 0 ) {
        return 5;
    }
    return 0;
}
Result is access violation

Original issue reported on code.google.com by andy.ya...@gmail.com on 3 Mar 2009 at 8:43

GoogleCodeExporter commented 9 years ago
Yes, current shared_ptr implementation has some bugs. There is a plan on 
rewriting 
it.

Now a new tr1::shared_ptr implementation there is, you can try to use it 
instead of 
stlx::shared_ptr or std::shared_ptr (it depends from branch).

Original comment by icestudent@gmail.com on 4 Mar 2009 at 3:10

GoogleCodeExporter commented 9 years ago
Its available in r505.

Original comment by icestudent@gmail.com on 4 Mar 2009 at 3:13

GoogleCodeExporter commented 9 years ago

Original comment by icestudent@gmail.com on 4 Mar 2009 at 3:28

GoogleCodeExporter commented 9 years ago
Complete std smart pointers are available in r508.

Original comment by icestudent@gmail.com on 4 Mar 2009 at 4:23