[Bug c++/13481] New: No destuctor assumed in a forward declared class when being used in template
ikm at pisem dot net
gcc-bugzilla@gcc.gnu.org
Tue Dec 23 19:00:00 GMT 2003
When trying to call the implied destructor in a forward declared class within a
template class, g++ 3.3 asserts this as an invalid usage of a forward
declaration. Everything was ok in g++ 3.2 and the code worked fine.
The following code shows the problem. It compiles and works fine on gcc 3.2, but
fails on gcc 3.3.
#include <iostream>
// Forward declaration
class Forward;
// Some template using T's destructor explicitly
template< class T >
class Template
{
T * object;
public:
Template() {}
Template( T * object_ ): object( object_ )
{}
void destruct()
{
// g++ 3.2 knew that Forward has a destructor at this point, but g++ 3.3
// does not think so these days.
object->~T();
}
};
// This class attempts using the template
class User
{
public:
Template< Forward > t;
User( Forward * f): t( f ) {}
void use()
{ t.destruct(); }
};
// Here actually comes the body of Forward
class Forward
{
public:
~Forward()
{
std::cerr << "Destructing Forward" << std::endl;
}
};
int main()
{
Forward * f = new Forward;
User user( f );
user.use();
return 0;
}
////////////////////////////////
With g++-3.2 -Wall, everything compiles fine without any warning and actually
works, outputting the "Destructing Forward" message as expected. g++-3.3 shows
the following:
$ g++-3.3 -v -Wall test.cc
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.3/specs
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib
--enable-nls --without-included-gettext --enable-__cxa_atexit
--enable-clocale=gnu --enable-debug --enable-java-gc=boehm
--enable-java-awt=xlib --enable-objc-gc i486-linux
Thread model: posix
gcc version 3.3.3 20031206 (prerelease) (Debian)
/usr/lib/gcc-lib/i486-linux/3.3.3/cc1plus -quiet -v -D__GNUC__=3
-D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=3 -D_GNU_SOURCE test.cc -D__GNUG__=3
-quiet -dumpbase test.cc -auxbase test -Wall -version -o /tmp/ccnjudqp.s
GNU C++ version 3.3.3 20031206 (prerelease) (Debian) (i486-linux)
compiled by GNU C version 3.3.3 20031206 (prerelease) (Debian).
GGC heuristics: --param ggc-min-expand=47 --param ggc-min-heapsize=32058
ignoring nonexistent directory "/usr/i486-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/3.3
/usr/include/c++/3.3/i486-linux
/usr/include/c++/3.3/backward
/usr/local/include
/usr/lib/gcc-lib/i486-linux/3.3.3/include
/usr/include
End of search list.
test.cc: In member function `void Template<T>::destruct() [with T = Forward]':
test.cc:38: instantiated from here
test.cc:24: error: invalid use of undefined type `struct Forward'
test.cc:4: error: forward declaration of `struct Forward'
I actually miss that functionality that allowed me to create nice smart pointers
in the past.
--
Summary: No destuctor assumed in a forward declared class when
being used in template
Product: gcc
Version: 3.3.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ikm at pisem dot net
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13481
More information about the Gcc-bugs
mailing list