This is the mail archive of the gcc-prs@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]

c++/113: Re: egcs c++ bug report



>Number:         113
>Category:       c++
>Synopsis:       operator delete[] does not receive original array size
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          analyzed
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 15 01:26:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     Robbie Gates <robbie@ics.mq.edu.au>
>Release:        2.95.2
>Organization:
Macquarie University
>Environment:
>Description:
 Original-Message-ID: <37BCDC14.E9F1C623@ics.mq.edu.au>
 Date: Fri, 20 Aug 1999 14:39:48 +1000
 

 Hi there,
   i think the following is a bug - please find attached the required
 stuff from according to http://egcs.cygnus.com/faq.html#bugreport,
 as generated by

 c++ -v --save-temps bug.cpp 

 my machine is a redhat 6.0 GNU/Linux system

 (robbie@elegia) uname -a
 Linux elegia.mpce.mq.edu.au 2.2.5-15 #2 Mon Jul 5 19:31:36 EST 1999 i686
 unknown
 (robbie@elegia) c++ -v
 Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs
 gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)

 On my machine, running the executable from the above compiler produces
 8
 8
 32
 328
 The executable from c++ -DWORKAROUND bug.cpp produces
 8
 8
 36
 36

 I believe the latter to be correct, and that the former to be incorrect.

 My reasoning is based on section 12.5 (class.free) of CD2 for C++.
 I believe the second argument passed to operator delete[] should be
 32, not 328, according to clause 9 of 12.5 assuming the compiler
 is meeting clause 3 of 12.5. With respect to the footnote, observe that
 the static type in the deletion expression is the same as
 the actual type of the object.

 The workaround code provided seems to solve the problem (at least
 in this example :-).

  - robbie
>How-To-Repeat:
#include <cstddef>
#include <iostream>

class A
{
public:
	void * operator new[] (size_t aS)
	{
		cout << aS << endl;
		return ::operator new(aS);
	}

	void operator delete[] (void * aPtr, size_t aS)
	{
		cout << aS << endl;
		::operator delete(aPtr);
	}
#ifdef WORKAROUND
	~A()
	{
	}
#endif
};

class B : public A
{
	int x;
};

int main()
{
	A * a = new A[4];
	delete[] a;
	B * b = new B[4];
	delete[] b;

	return 0;
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:

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