From: peter koch larsen on
On 22 Apr., 04:43, internetpet <internet...(a)hotmail.com> wrote:
[snip]
> If you run this you'll see that the Clazz destructor will not be
> called when BigClazz does "delete pclazz;" in it's own destructor. But
> if you replace the forward declaration in BigClazz (class Clazz;) with
> an include
> (#include "Clazz.h") then it works.
>
> Any idea why?
>
> Thanks
> Eric

Others already mentioned why you had problems. My recommandation is to
set the options of your compiler in a way that provokes a warning
message. If you can't provoke your compiler to do that, you should
seriously consider switching compilers or at least check your program
with another compiler (gcc comes to mind). Actually, double-checking
your programs with another compiler is often a good idea.

/Peter

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Vidar Hasfjord on
On Apr 22, 6:13 pm, Brendan <catph...(a)catphive.net> wrote:
> What I'm actually iffy on, is why you can compile code that deletes a
> pointer to an incomplete type at all. This compiles with only a
> warning about deleting a pointer to an incomplete type on VC9.

I agree that the standard should at least require a diagnostic if
doesn't already do so. I guess forbidding it is difficult because it
actually works fine when the type has a trivial destructor.

An interesting question is what is the minimal type information
required for the compiler to handle this correctly? Could a language
extension allow this to be handled without requiring the full type to
be revealed (and thus require the user to break encapsulation or
redesign the class hierarchy). Could the following be enough?

virtual class Clazz; // I have a virtual destructor, promise!

This topic, partially complete types, was discussed earlier in this
group.

http://groups.google.com/group/comp.lang.c++.moderated/browse_frm/thread/9f05934ee81e120b

Regards,
Vidar Hasfjord


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Triple-DES on
On 22 Apr, 19:07, marlow.and...(a)googlemail.com wrote:

[snip]
> The type must be known for delete blah to be compilable.

The code is not ill-formed, merely UB, so a conforming compiler could
compile the code without warning.

> Hence your code will not compile. Here's the error I got from gcc:
>
> BigClazz.cpp: In destructor �BigClazz::~BigClazz()�:
> BigClazz.cpp:5: warning: possible problem detected in invocation of
> delete operator:
> BigClazz.cpp:5: warning: invalid use of undefined type �struct Clazz�
> BigClazz.h:1: warning: forward declaration of �struct Clazz�
> BigClazz.cpp:5: note: neither the destructor nor the class-specific
> operator delete will be called, even if they are declared when the
> class is defined.
>
> Says it all, I think.
> You wouldn't be using a Micro$oft compiler by any chance?

warning C4150: deletion of pointer to incomplete type 'Clazz'; no
destructor called

Says it all, I think, and in just one line :)

DP


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]