🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #970

Re: operator new with placement

#970
From: Mike Stump
Date: Tue, 15 Sep 1992 07:59
53 lines
2513 bytes
The non-standard workaround is to use the new { ... } ... syntax
instead of the new ( ... ) ... syntax.

It is still a known problem, and one day will be fixed.

> From: jorgnsn@qucis.queensu.ca (John Jorgensen)
> Message-Id: <1992Sep14.212640.742@qucis.queensu.ca>
> Organization: Computing & Information Science, Queen's University at Kingston
> Date: Mon, 14 Sep 1992 21:26:40 GMT
> Apparently-To: gnu-g++-bug@watmath.uwaterloo.ca
> To: bug-g++@prep.ai.mit.edu

> Are there any known problems with g++ 2.2.2's handling of the new operator
> when it is given an explicit placement option?  While trying to understand
> a problem g++ was having with the output of a code generator, I tried
> it on the following trivial example of explicit placement, simplified

>     // example of placement argument to new, taken from Lippmann, "C++ Primer".

>     #include <iostream.h>
>     #include <new.h>

>     class Foo {
>     public:
> 	int val;
> 	Foo() {val = 0;}
>     };

>     char *buf = new char[sizeof(Foo)];

>     main() {
> 	Foo *pb = new ((void *)buf) Foo;

> 	// check that objects were placed in buf.
> 	if ( (char*)pb == buf)
> 	    cout << "Operator new worked!: pb: " << pb << " buf: " << (void*)buf << endl;

> 	return 0;
>     }

> This works with our copy of AT&T C++ 3.0, but g++ gets a syntax error:

>     g++ -v -o new new.c
>     Reading specs from /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.2.2/specs
>     gcc version 2.2.2
>      /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.2.2/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix new.c /usr/tmp/cca00711.i
>      GNU CPP version 2.2.2 (sparc)
>       /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.2.2/cc1plus /usr/tmp/cca00711.i -quiet -dumpbase new.cc -version -o /usr/tmp/cca00711.s
>       GNU C++ version 2.2.2 (sparc) compiled by GNU C version 2.2.2.
>       new.c: In function `int  main ()':
>       new.c:15: parse error before `('

> I am doing something dumb?  Is there a workaround?
Technical Details
Message-ID: <9209150759.AA00559@cygnus.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!wupost!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!cygnus.com!mrs

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!wupost!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!cygnus.com!mrs
From: mrs@cygnus.com (Mike Stump)
Subject: Re:  operator new with placement
Message-ID: <9209150759.AA00559@cygnus.com>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Tue, 15 Sep 1992 07:59:41 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 54