------- Additional Comments From reichelt at gcc dot gnu dot org  2004-10-28 15:30 
-------
Here's a condensed version of Wolfgang's testcase:

====================================
int i=1;

class A;

template<int> struct B
{
    A *p;

    ~B()
    {
        --i;
        p=0;
        if(p) delete p;
    }
};

class C : B<0> {};

class A { C c; };

int main()
{
    { C c; }
    return i;
}
====================================

On i686-pc-linux-gnu this returns 0 except for gcc 3.3.x where it returns 1.

However, I'm unsure whether this is valid at all:
If I remove the template, the compiler says:

x.cc: In destructor `B::~B()':
x.cc:13: warning: possible problem detected in invocation of delete operator:
x.cc:13: warning: invalid use of undefined type 'struct A'
x.cc:3: warning: forward declaration of 'struct A'
x.cc:13: note: neither the destructor nor the class-specific operator delete
will be called, even if they are declared when the class is defined.

The warning seems to be justified. To construct A's destructor one needs C's,
which needs A's via C's base class B<0>.

Maybe we are invoking undefined behavior here, so looking for a bug would
become moot.

Comments?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648

Reply via email to