Article View: gnu.g++.bug
Article #960operator new with placement
From: John Jorgensen
Date: Mon, 14 Sep 1992 21:26
Date: Mon, 14 Sep 1992 21:26
48 lines
2240 bytes
2240 bytes
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
from Stanley Lippman's "C++ Primer, Second Edition":
// 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?
Thanks.
--
John Jorgensen jorgnsn@qucis.queensu.ca (613) 545 6784
Systems Programmer, Dept. of Computing Science, Queen's University
Technical Details
Message-ID:
<1992Sep14.212640.742@qucis.queensu.ca>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!qucis.queensu.ca!jorgnsnShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!qucis.queensu.ca!jorgnsn From: jorgnsn@qucis.queensu.ca (John Jorgensen) Subject: operator new with placement Message-ID: <1992Sep14.212640.742@qucis.queensu.ca> Sender: gnulists@ai.mit.edu Organization: Computing & Information Science, Queen's University at Kingston Distribution: gnu Date: Mon, 14 Sep 1992 21:26:40 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 49