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

Reply via email to