bug-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(no subject)


From: Sean Clarke
Subject: (no subject)
Date: Sat, 28 Oct 2000 23:30:03 +0100

Hi,
        I posted this in gnu.gcc.bug, then realised it would be more
appropriate here, sorry if this appears more than once, I posted it last
week and haven't seen it appear in the list :-{

GCC GNATS BUG NO: 670

There appears to be a bug in gcc, can someone confirm ?. Attached to the
gnats bug report (and listed below) is a cpp file that demonstrates the
problem which seems to cause the compiler to call one (or more) too many
destructors, we detected the problem whilst porting an HP application to
Linux and traced the core dumps etc. to some code that wasn't too well
written (i.e. it was passing the object by value instead of by
reference) anyway it appears the compiler does something horrible, calls
too many destructors, and when we try to delete the object/use the
object.... BANG.

Is anyone able to fix this problem ?

--

regards

Sean Clarke
=============================================
www.linux-software.clara.co.uk
address@hidden
Linux... for those whose IQ is greater than 98 !!!

BUG TEST CODE :


#include <utility>
#include <list>
#include <iostream>

class Counter
{
public:
        Counter();
        ~Counter() throw();
        Counter( const Counter& rhs);

        static int count() { return count_; }
private:
        static int count_;
        int state;
};

Counter::Counter()
{
        ++count_;
        cout << "Counter::Counter() count_=" << count_ << endl;
}

Counter::~Counter() throw()
{
        --count_;
        cout << "Counter::~Counter() count_=" << count_ << endl;
}

Counter::Counter( const Counter& rhs)
{
        ++count_;
        cout << "Counter::Counter() count_=" << count_ << endl;
}

int Counter::count_ = 0;

class Returns_pair
{
public:
        typedef pair< Counter, Counter > Returns;

        Returns pair() const;
};

Returns_pair::Returns Returns_pair::pair() const
{
        return Returns();
}

class Holder
{
public:
        Holder( Counter counter ) : counter_( counter ) {}
private:
        Counter counter_;
};

int main()
{
        cout << "In main" << endl;

        list< Holder > list;

        Returns_pair returns_pair;

        list.push_back( Holder( returns_pair.pair().first ) );

        cout << Counter::count() << " should be 1" << endl;

        return 0;
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]