This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C++: delete of incomplete type is undefined, not ill-formed
- From: Gabriel Dos Reis <gdr at codesourcery dot com>
- To: Alexandre Oliva <aoliva at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: 16 May 2002 13:20:50 +0200
- Subject: Re: C++: delete of incomplete type is undefined, not ill-formed
- Organization: CodeSourcery, LLC
- References: <orvg9oo5rb.fsf@free.redhat.lsd.ic.unicamp.br>
Alexandre Oliva <aoliva@redhat.com> writes:
| [1 <text/plain>]
| Once again, I'm not sure I can publish the testcase I got from the
| customer, so I'll describe the problem. When we delete a variable
| whose type is pointer-to-incomplete-type (say, a forward-declared
| class type), we emit an error message. However, [expr.delete]/5 says
| this invokes undefined behavior,
I don't think it says exactly that. THere are the exact words:
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.
(Emphasis is mine).
| not that it's ill-formed, so I've
| arranged for we to emit a warning and generate code that simply calls
| the global delete operator, which is the best we can do. Failing to
| invoke a destructor, if there is one, falls into the
| undefined-behavior umbrella.
I'm not sure I'm confortable with your proposed patch. What are the
concrte wins? For that matter:
1.3.12 undefined behavior
behavior, such as might arise upon use of an erroneous program
construct or erroneous data, for which this International Standard
imposes no requirements. Undefined behavior may also be expected
when this International Standard omits the description of any
explicit definition of behavior. [Note: permissible unde-fined
behavior ranges from ignoring the situation completely with
unpredictable results, to behaving during translation or program
execution in a documented manner characteristic of the environment
(with or with-out the issuance of a diagnostic message), to
terminating a translation or execution (with the issuance of a
diagnostic message). ...]
-- Gaby