🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Bug overloading operator new, g++ 2.3.1

#42
From: Klamer Schutte
Date: Wed, 04 Nov 1992 17:58
43 lines
1936 bytes
The operator new can still not be overloaded in the way ARM specifies (IMHO).
Allocating a class instance with a constructor with arguments results in a
parse error.

The code is:

// Get size_t by including stdlib.h
#include	<stdlib.h>

class Y {
	// ...
public:
	void *operator new(size_t size, int flag);
	Y();
	Y(const char *);
};

Y*	p1 = new(7) Y;
Y*	p2 = new(7) Y("This should be OK");

And the compiler fails on the line with "This should be OK" with the following
diagnostic:

1 klamer@mi7 16:55 14> g++ -v new.cc
Reading specs from /usr/local/lib/gcc-lib/sun4/2.3.1/specs
gcc version 2.3.1
 /usr/local/lib/gcc-lib/sun4/2.3.1/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG
__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__spa
rc -D__sun -D__unix new.cc /tmp/cca01711.i
GNU CPP version 2.3.1 (sparc)
 /usr/local/lib/gcc-lib/sun4/2.3.1/cc1plus /tmp/cca01711.i -quiet -dumpbase new.
cc -version -o /tmp/cca01711.s
GNU C++ version 2.3.1 (sparc) compiled by GNU C version 2.3.1.
new.cc:13: parse error before `)'

Sun C++ does allow the code above. g++ 2.2.1 does if the new{7} is used
instead of new(7). (And so does g++ 2.3.1, but with warnings at -Wall).

Klamer

Klamer Schutte			Tel: +31-53-892778	Fax: +31-53-340045
Faculty of electrical engineering -- University of Twente, The Netherlands
preferred: klamer@mi.el.utwente.nl     SMTP: klamer@utelmi01.el.utwente.nl
Technical Details
Message-ID: <9211041558.AA03706@mi.el.utwente.nl>
Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!sun-barr!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!mi.eltn.utwente.NL!klamer

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!sun-barr!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!mi.eltn.utwente.NL!klamer
From: klamer@mi.eltn.utwente.NL (Klamer Schutte)
Subject: Bug overloading operator new, g++ 2.3.1
Message-ID: <9211041558.AA03706@mi.el.utwente.nl>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Wed, 4 Nov 1992 17:58:17 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 44