From: mrs@cygnus.com (Mike Stump)
Subject: operator delete
Organization: GNUs Not Usenet
Distribution: gnu
Date: Fri, 4 Sep 1992 20:26:19 GMT

This problem should not exist in the next release of gcc.

In the future please report all g++ bugs to the

        bug-g++@prep.ai.mit.edu

list, thanks.  If they are back-end bugs, they can be reported here,
but please let us know if you think the problem is in the back-end.

You don't need to resubmit this one.

> Message-Id: <9207141559.AA00602@ariel.cs.trinity.edu>
> From: jhowland@ariel.cs.trinity.edu (Dr. John E. Howland)
> Date: Tue, 14 Jul 92 15:59:21 GMT

> I am having a problem with g++ 2.2.1 when overiding the operators
> new and delete.  I have tried to illustrate this problem with a
> simple example.  The problem is that the compiler fails to supply
> the right number of arguments to a call to overiden delete which has
> been defined with two arguments.  See section r.12.5, page 577 of
> Stroustrup, "The C++ Programming Language", 2nd Edition.

> The example follows:

> 	{71} snoopy:jhowland /user1/users/jhowland % cd gplus.delete.prob
> 	{72} snoopy:jhowland /user1/users/jhowland/gplus.delete.prob % l
> 	total 128
> 	drwxr-x---   2 jhowland develop      512 Jul  1 17:00 .
> 	drwxr-xr-x  32 jhowland develop     2048 Jul  1 17:08 ..
> 	-rw-r-----   1 jhowland develop       70 Jul  1 16:00 Makefile
> 	-rwxr-x---   1 jhowland develop    60232 Jul  1 17:00 foo
> 	-rw-r-----   1 jhowland develop      859 Jul  1 16:57 foo.C
> 	{73} snoopy:jhowland /user1/users/jhowland/gplus.delete.prob % cat foo.C
> 	#include <iostream.h>
> 	#include <stddef.h>
> 	
> 	class date
> 	{
> 			int year, month, day;
> 	
> 			public:
> 					void setdate(int, int, int);
> 					void printdate(void);
> 					void* operator new(size_t);
> 					void operator delete(void*, size_t);
> 	};
> 	
> 	class otherdate : public date
> 	{
> 			int junk;       //something else which is private
> 	};
> 	
> 	void date::setdate(int yr, int mo, int dy)
> 	{
> 			year = yr;
> 			month = mo;
> 			day = dy;
> 	}
> 	
> 	void date::printdate(void)
> 	{
> 			cout << month << '/' << day << '/' << year << '\n';
> 	}
> 	
> 	void* date::operator new(size_t size)
> 	{
> 			return ::new char[size];
> 	}
> 	
> 	void date::operator delete(void *ptr, size_t size)
> 	{
> 			::delete ptr;
> 	}
> 	
> 	int main(void)
> 	{
> 			otherdate day;
> 			otherdate *dayPtr;
> 	
> 			day.setdate(1941,7,28);
> 			day.printdate();
> 	
> 			dayPtr = new otherdate;
> 	
> 			dayPtr->setdate(1941,7,28);
> 			dayPtr->printdate();
> 	
> 	//      delete dayPtr;
> 			date::operator delete(dayPtr, sizeof(otherdate));
> 	
> 	}
> 	{74} snoopy:jhowland /user1/users/jhowland/gplus.delete.prob % make
> 			g++ -I/usr/local/Gnu/lib/gcc/2.2.1/g++-include -o foo foo.C
> 	{75} snoopy:jhowland /user1/users/jhowland/gplus.delete.prob % foo
> 	7/28/1941
> 	7/28/1941

> Now, editing main so that it reads as:

> int main(void)
> {
>         otherdate day;
>         otherdate *dayPtr;

>         day.setdate(1941,7,28);
>         day.printdate();

>         dayPtr = new otherdate;

>         dayPtr->setdate(1941,7,28);
>         dayPtr->printdate();

>         delete dayPtr;
> //      date::operator delete(dayPtr, sizeof(otherdate));

> }

> yields the following:

> 	{77} snoopy:jhowland /user1/users/jhowland/gplus.delete.prob % make
> 			g++ -I/usr/local/Gnu/lib/gcc/2.2.1/g++-include -o foo foo.C
> 	foo.C: In function `int  main ()':
> 	foo.C:55: too few arguments for method `operator delete'
> 	cp-method.c:2217: failed assertion `rval != error_mark_node'
> 	/usr/local/Gnu/gcc: Internal compiler error: program cc1plus got fatal signal 6
> 	Make: *** Error: Update of `all' terminated with exit code 1
> 	Make:            [line 2 in /user1/users/jhowland/gplus.delete.prob/Makefile]
> 	
> 	{78} snoopy:jhowland /user1/users/jhowland/gplus.delete.prob %

Newsgroups: gnu.g++.bug