This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

explicit call of destructor of pointer objects in template functions


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
	.file	"junk1.cpp"
	.version	"01.01"
.stabs "/tmp/",100,0,0,.Ltext0
.stabs "junk1.cpp",100,0,0,.Ltext0
.text
.Ltext0:
	.stabs	"gcc2_compiled.", 0x3c, 0, 0, 0
.stabs "int:t(0,1)=r(0,1);0020000000000;0017777777777;",128,0,0,0
.stabs "char:t(0,2)=r(0,2);0;127;",128,0,0,0
.stabs "long int:t(0,3)=r(0,1);0020000000000;0017777777777;",128,0,0,0
.stabs "unsigned int:t(0,4)=r(0,1);0000000000000;0037777777777;",128,0,0,0
.stabs "long unsigned int:t(0,5)=r(0,1);0000000000000;0037777777777;",128,0,0,0
.stabs "long long int:t(0,6)=r(0,1);01000000000000000000000;0777777777777777777777;",128,0,0,0
.stabs "long long unsigned int:t(0,7)=r(0,1);0000000000000;01777777777777777777777;",128,0,0,0
.stabs "short int:t(0,8)=r(0,8);-32768;32767;",128,0,0,0
.stabs "short unsigned int:t(0,9)=r(0,9);0;65535;",128,0,0,0
.stabs "signed char:t(0,10)=r(0,10);-128;127;",128,0,0,0
.stabs "unsigned char:t(0,11)=r(0,11);0;255;",128,0,0,0
.stabs "float:t(0,12)=r(0,1);4;0;",128,0,0,0
.stabs "double:t(0,13)=r(0,1);8;0;",128,0,0,0
.stabs "long double:t(0,14)=r(0,1);12;0;",128,0,0,0
.stabs "complex int:t(0,15)=s8real:(0,1),0,32;imag:(0,1),32,32;;",128,0,0,0
.stabs "complex float:t(0,16)=r(0,16);4;0;",128,0,0,0
.stabs "complex double:t(0,17)=r(0,17);8;0;",128,0,0,0
.stabs "complex long double:t(0,18)=r(0,18);12;0;",128,0,0,0
.stabs "bool:t(0,19)=@s8;-16;",128,0,0,0
.stabs "void:t(0,20)=(0,20)",128,0,0,0
.stabs "__wchar_t:t(0,21)=r(0,1);0020000000000;0017777777777;",128,0,0,0
.stabs "__vtbl_ptr_type:t(0,22)=*(0,23)=f(0,1)",128,0,0,0
	.align 16
.stabs "g__FPCc:F(0,20)",36,0,3,g__FPCc
.stabs "x:p(0,24)=*(0,2)",160,0,3,8
.globl g__FPCc
	.type	 g__FPCc,@function
g__FPCc:
.LFB1:
.stabn 68,0,3,.LM1-g__FPCc
.LM1:
	pushl %ebp
.LCFI0:
	movl %esp,%ebp
.LCFI1:
.stabn 68,0,3,.LM2-g__FPCc
.LM2:
.LBB2:
	movl 8(%ebp),%eax
	pushl %eax
.LCFI2:
	call f__H1ZPCc_X01_i
	addl $4,%esp
.LBE2:
	jmp .L2
	jmp .L1
	.align 16
.L2:
.stabn 68,0,3,.LM3-g__FPCc
.LM3:
.L1:
	movl %ebp,%esp
	popl %ebp
	ret
.LFE1:
.Lfe1:
	.size	 g__FPCc,.Lfe1-g__FPCc
.stabn 192,0,0,.LBB2-g__FPCc
.stabn 224,0,0,.LBE2-g__FPCc
.Lscope0:
.stabs "",36,0,0,.Lscope0-g__FPCc

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]