--- Mike Nordell <[EMAIL PROTECTED]> wrote:
> Joaqu�n Cuenca Abela wrote:
> 
> > #define DELETEP(ptr) \
> > do {} while(sizeof(*ptr) == 0); \
> > delete ptr; \
> > ptr = NULL;
> >
> > to prevent trying to delete a type not yet known
> to the compiler,
> > because the standard doesn't forces a compiler to
> issue a warning in
> > this case, and the result is undefined (the
> compiler can not known if
> > the type has a trivial destructor).
> 
> ???
> 
> How would the compiler allow deletion of an
> incomplete type that it
> therefore obviously has no accessible destructor
> for?

don't ask me...

> IMO a reasonable
> compiler should issue diagnostics, and AFAIK any
> compiler would have to
> abort translation.

would != should, unfortunately...

When you try with trivial examples with gcc, it aborts
translation, but I few months ago I was bitten by this
very same problem.

It was a class with a pimpl (using first
std::auto_ptr, and later boost::smart_ptr).  My class
had a trivial destructor, so I (erronously) didn't
write it explicitely.  I was missing that the compiler
was going to write a default **inline** destructor.

When I tried to use this class with std::auto_ptr, it
was working fine, but when I switched to
std::smart_ptr, the compiler it started to complain
about Impl not being a complete type.

First I though "of course it's not a complete type,
that's the whole point!!?".  Seconds after I realized
my error, and I just though "oh my... I'm a moron"

I then read the whole checked_delete history.  From
the boost webpage:

==============================================

Background
The C++ Standard specifies that delete on a pointer to
an incomplete types is undefined behavior if the type
has a non-trivial destructor in  [expr.delete] 5.3.5
paragraph.  No diagnostic is required.  Some but not
all compilers issue warnings if the type is incomplete
at point of deletion.

===============================================

Cheers,


=====
Joaquin Cuenca Abela
[EMAIL PROTECTED]

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

Reply via email to