This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/58114] allow turning the warning about deleting a pointer of incomplete type into an error


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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-04-16
     Ever confirmed|0                           |1
           Severity|enhancement                 |normal

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Teodor Petrov from comment #1)
> BTW: Do someone has an explanation why this is allowed in the standard?

Because it's only a problem if the type has a non-trivial destructor or an
overloaded operator delete. For a type with a trivial destructor (such as a
POD) all that needs to be done is deallocate the memory.

The standard says:

"If the object being deleted has incomplete class type at the point of deletion
and the complete class has a non-trivial destructor or a deallocation function,
the behavior is undefined."

Since the compiler can't know if an incomplete type has a trivial destructor or
not, it can only warn, not give a hard error. If you want to make it a hard
error in your own program you should be able to, so confirming.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]