bug in gcc version 2.95.2 19991024 (release): member initialization with new

Erik Eckstein Eckstein@atair.co.at
Wed Jun 14 07:48:00 GMT 2000


Command line:

	bin/g++ -S test.c

Compiler version:

	2.95.2 19991024 (release)

Target:

	Intel x86

Source code:

	class X
	{
	 public:
	        X(int n);
	        int *a;
	};

	X::X(int n) : a(new (int[n]))
	{ }

Behaviour:

	The size argument to new (sizeof(int) * n) is incorrect. It depends
on the previous value of the ebx register.

Assembler output:

	[...]
	__1Xi:
	.LFB1:
	        pushl %ebp
	.LCFI0:
	        movl %esp,%ebp
	.LCFI1:
	        subl $12,%esp
	.LCFI2:
	        pushl %edi
	.LCFI3:
	        pushl %esi
	.LCFI4:
	        pushl %ebx
	.LCFI5:
	        movl 8(%ebp),%esi
	        addl $-12,%esp
	        leal 1(%ebx),%eax			<= correct
instruction would be: movl 12(%ebp),%eax
	        leal 0(,%eax,4),%edx
	        pushl %edx
	.LCFI6:
	        call __builtin_vec_new
	[...]



More information about the Gcc-bugs mailing list