🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Operator new Question

#1608
From: Steve Clamage
Date: Fri, 04 Aug 1995 22:45
31 lines
1243 bytes
In article kav@bmtlh10.bnr.ca, John Hickin <hickin@bnr.ca> writes:
>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?

The results of using "delete" on a pointer value obtained from a placement-
new are undefined. Any result is allowed. It is invalid C++, but no
diagnostic is required.
---
Steve Clamage, stephen.clamage@eng.sun.com
Technical Details
Message-ID: <3vu7te$ql4@engnews2.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!usenet
References: <3vu2gv$kav@bmtlh10.bnr.ca>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!usenet
From: clamage@Eng.Sun.COM (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: Operator new Question
Date: 4 Aug 1995 22:45:02 GMT
Organization: Sun Microsystems Inc.
Message-ID: <3vu7te$ql4@engnews2.Eng.Sun.COM>
References: <3vu2gv$kav@bmtlh10.bnr.ca>
Reply-To: clamage@Eng.Sun.COM
NNTP-Posting-Host: taumet.eng.sun.com