🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1603

Operator new Question

#1603
From: John Hickin
Date: Fri, 04 Aug 1995 21:13
34 lines
1307 bytes
I accidently discovered that the following code compiles and executes using my
favourite compiler:

#include <iostream.h>
#include <stddef.h>

void* operator new(unsigned sz,const char*,int)
{
  return ::operator new(sz);
}

struct Foo { Foo(); ~Foo(); };

Foo::Foo()  { cerr << "Foo::Foo[this==" << (void*)this << ']' << endl; }
Foo::~Foo() { cerr << "Foo::~Foo[this==" << (void*)this << ']' << endl; }

main()
{
  Foo* p = new(__FILE__,__LINE__) Foo[ 42 ];
  delete[] p;
}



(1) Is it legal C++?
(2) If so, what should the behavior be?

In my environment (HP-UX 9.x, C++ A.03.05) the Foo::Foo's are called but the
Foo::~Foo's are not called.  If i change new(__FILE__,__LINE__) to just new the
destructors get called as expected.

-- 
John Hickin      Bell-Northern Research, Montreal, Quebec
(514) 765-7924   hickin@bnr.ca
Technical Details
Message-ID: <3vu2gv$kav@bmtlh10.bnr.ca>
Path: arc1-ca.pugleaf.net!bmtlh10.bnr.ca!news

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!bmtlh10.bnr.ca!news
From: John Hickin <hickin@bnr.ca>
Newsgroups: comp.std.c++
Subject: Operator new Question
Date: 4 Aug 1995 21:13:03 GMT
Organization: Bell-Northern Research
Message-ID: <3vu2gv$kav@bmtlh10.bnr.ca>
NNTP-Posting-Host: bmtlh520.bnr.ca
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 1.1 (X11; I; HP-UX A.09.01 9000/715)
X-URL: news:comp.std.c++