explicit call of destructor of pointer objects in template functions

Johannes Sixt Johannes.Sixt@telecom.at
Tue Jun 1 11:22:00 GMT 1999


k6!525> cat junk1.cpp

template<class T> f(T v) { v.~T(); }
void g(const char* x) { f(x); }

k6!526> /usr/lib/gcc-lib/i486-linux/egcs-2.91.66/cc1plus -g junk1.cpp 
 int f(T) void g(const char *) int f<const char *>(const char *)
junk1.cpp:3:   instantiated from here
junk1.cpp:2: Internal compiler error.
junk1.cpp:2: Please submit a full bug report to `egcs-bugs@egcs.cygnus.com'.
junk1.cpp:2: See <URL: http://egcs.cygnus.com/faq.html#bugreport > for details.
k6!527> gcc -v
Reading specs from /usr/lib/gcc-lib/i486-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
k6!528> uname -a
Linux k6 2.2.5 #3 Fri Apr 2 17:04:34 MEST 1999 i586 unknown
k6!529> 

This is a SuSE Linux 6.1 system (using glibc 2.0.7).

Short explanation: The template function f explicitly calls the destructor of
an object. According to draft 2 of C++ standard, calling the destructor of a
scalar type should do nothing. I think (but are not sure) that const char* is a
scalar type, so the example should compile. It does compile if x is of type int
instead of const char*.

Note that the destructor is called for v, not for the object that v points to!

I get the same error for a function where it actually makes sense to explicitly
call the destructor of a const char*. :-)

Find attached junk1.s, the assembler output generated until the error occurs.

-- Hannes


More information about the Gcc-bugs mailing list