C++: delete of incomplete type is undefined, not ill-formed
Gabriel Dos Reis
gdr@codesourcery.com
Thu May 16 05:54:00 GMT 2002
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
More information about the Gcc-patches
mailing list