public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/43452] New: Array delete causes error on incomplete type @ 2010-03-20 0:38 yy2bggggs at gmail dot com 2010-03-20 0:57 ` [Bug c++/43452] " redi at gcc dot gnu dot org ` (2 more replies) 0 siblings, 3 replies; 4+ messages in thread From: yy2bggggs at gmail dot com @ 2010-03-20 0:38 UTC (permalink / raw) To: gcc-bugs This code: class Foo; int main() { Foo* p; delete [] p; } Produces this error: dt.cpp:6: error: invalid use of incomplete type `struct Foo' dt.cpp:1: error: forward declaration of `struct Foo' ...but shouldn't it compile? With: g++ -c -std=c++98 ...on 4.3.4 20090804 (release) 1 in Cygwin; and: ...on 4.1.2 20080704 (Red Hat 4.1.2-44) The ordinary form works just fine; replace "delete [] p;" with "delete p;", and: dt.cpp: In function `int main()': dt.cpp:6: warning: possible problem detected in invocation of delete operator: dt.cpp:5: warning: `p' has incomplete type dt.cpp:1: warning: forward declaration of `struct Foo' dt.cpp:6: note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined. ...on 4.3.4 20090804 system, and: ...on 4.1.2 20080704 system. -- Summary: Array delete causes error on incomplete type Product: gcc Version: unknown Status: UNCONFIRMED Severity: minor Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: yy2bggggs at gmail dot com GCC host triplet: 4.3.4 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43452 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/43452] Array delete causes error on incomplete type 2010-03-20 0:38 [Bug c++/43452] New: Array delete causes error on incomplete type yy2bggggs at gmail dot com @ 2010-03-20 0:57 ` redi at gcc dot gnu dot org 2010-03-20 1:03 ` redi at gcc dot gnu dot org 2010-03-20 11:27 ` bangerth at gmail dot com 2 siblings, 0 replies; 4+ messages in thread From: redi at gcc dot gnu dot org @ 2010-03-20 0:57 UTC (permalink / raw) To: gcc-bugs ------- Comment #1 from redi at gcc dot gnu dot org 2010-03-20 00:57 ------- It's undefined behaviour -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43452 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/43452] Array delete causes error on incomplete type 2010-03-20 0:38 [Bug c++/43452] New: Array delete causes error on incomplete type yy2bggggs at gmail dot com 2010-03-20 0:57 ` [Bug c++/43452] " redi at gcc dot gnu dot org @ 2010-03-20 1:03 ` redi at gcc dot gnu dot org 2010-03-20 11:27 ` bangerth at gmail dot com 2 siblings, 0 replies; 4+ messages in thread From: redi at gcc dot gnu dot org @ 2010-03-20 1:03 UTC (permalink / raw) To: gcc-bugs ------- Comment #2 from redi at gcc dot gnu dot org 2010-03-20 01:03 ------- Hmm, on second thoughts... Technically that program has undefined behaviour because p does not have a value that comes from a previous new expression, however this variation is not undefined as long as Foo has a trivial destructor, and f returns a pointer to an array of Foo: class Foo; Foo* f(); int main() { Foo* p = f(); delete [] p; } -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43452 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/43452] Array delete causes error on incomplete type 2010-03-20 0:38 [Bug c++/43452] New: Array delete causes error on incomplete type yy2bggggs at gmail dot com 2010-03-20 0:57 ` [Bug c++/43452] " redi at gcc dot gnu dot org 2010-03-20 1:03 ` redi at gcc dot gnu dot org @ 2010-03-20 11:27 ` bangerth at gmail dot com 2 siblings, 0 replies; 4+ messages in thread From: bangerth at gmail dot com @ 2010-03-20 11:27 UTC (permalink / raw) To: gcc-bugs ------- Comment #3 from bangerth at gmail dot com 2010-03-20 11:26 ------- (In reply to comment #2) > class Foo; > Foo* f(); > int main() { > Foo* p = f(); > delete [] p; > } I can't see how the compiler could possibly do anything useful in this case if Foo is incomplete. I can't find any statement that would say that the code is ill-formed, however. If there really is no such statement, I still don't think we should make it a priority to compile this code without an error. W. -- bangerth at gmail dot com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bangerth at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43452 ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-03-20 11:27 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2010-03-20 0:38 [Bug c++/43452] New: Array delete causes error on incomplete type yy2bggggs at gmail dot com 2010-03-20 0:57 ` [Bug c++/43452] " redi at gcc dot gnu dot org 2010-03-20 1:03 ` redi at gcc dot gnu dot org 2010-03-20 11:27 ` bangerth at gmail dot com
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).