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]

bug when overloading delete with multiple parameters



Hi,

I have tried to overload delete and to add an extra parameter.
It turned out that g++ was not able to cope with this
additional parameter just as new is. Furthermore it is
also not possible to call the nothrow variant of delete

e.g.

char * p ;
p = new(nothrow) char ; // works
delete(nothrow) p ;     // does not work

It would be convenient for debugging if delete is able to handle
extra parameters just in the same way es new can. One could overload
the new and delete to take an extra parameter e.g. "this" and make
a protocoll of how many calls to new and delete are performed by a
single object. The only thing one would have to do is to replace
all new and delete call through a preprocessor define

#define new    new(this)
#define delete delete(this)

/**********************************************************************
 **
 ** tst.c 
 ** 
 ** compile with: g++ -v tst.c
 **
 ** GNU C++ version 2.95.2 19991024 (release) (i686-pc-linux-gnu) compiled by GNU C version 2.7.2.3.
 ** tst.c: In function `int main(...)':
 ** tst.c:34: type `int' argument given to `delete', expected pointer
 ** tst.c:34: parse error before `;'
 ** tst.c:35: type `int' argument given to `delete', expected pointer
 ** tst.c:35: parse error before `;'
 ***********************************************************************************/

#include <stdio.h>

void * operator new (size_t i, int a)
 {
 printf ("-- new %d\n",i) ;
 return ::operator new (i) ;
 }

void operator delete (void * o,int a)
 {
 printf ("-- delete %p\n",o) ;
 return std::operator delete (o) ;
 }

void main (void)
 {
 char * a = new(1) char ;
 int  * b = new(1) int ;

 delete(1) b ;  // this doesn't work but it should
 delete(1) a ;  // just as it works for new
                // (e.g. new(nothrow) and delete(nothrow))

 // delete(b,1) ;  // this doesn't work and it is ok
 // delete(a,1) ;  // this doesn't work and it is ok

 // operator delete(b,1) ;  // this works
 // operator delete(a,1) ;  // this works
 }

regards,
Thorsten

------------------------------------------------------------------
 Thorsten.Schmitt@in.tum.de       www9.in.tum.de/people/schmittt/
 Munich University of Technology  tel +49 (0)89 / 48095 - 210
 Department of Computer Science   fax +49 (0)89 / 48095 - 120
 Orleansstrasse 34, D-81667 Muenchen




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