🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

badly generated operator new in template

#1436
From: yb
Date: Wed, 27 Jan 1993 03:06
55 lines
2236 bytes
g++ 2.3.3 generates incorrect operator new when it is defined in a template class. 
Looking at the assembly code, I noticed that the allocated-size is not loaded
from the good register.

The following piece of code illustrates this problem :

% cat foo.cc
#include <stddef.h>
#include <stdio.h>

template <class T>
class A {
public:
	T v;
	void* operator new (size_t);
};

template <class T> void*
A<T> :: operator new (size_t s)
{
	printf ("%d\n", s);
	return new char [s];
}

main ()
{
	printf ("%d\n", sizeof(A<int>));
	A<int>* a = new A<int>;
}
% gcc -v
Reading specs from /usr/local/gnu/lib/gcc-lib/hp700-hpux/2.3.3/specs
gcc version 2.3.3
% gcc foo.cc
% a.out
4
-278528
Virtual memory exceeded in `new'
----------------
Interesting !

+--------------------------+------------------------------------+
|                          |       E-mail : yb@lri.lri.fr       |
|     Yves Berteaud        |                yb@FRLRI61.BITNET   |
|                          |                                    |
|       +-=-+-=-+          |       Voice :  33 (1) 69-41-69-10  |
|                          |       Fax   :  33 (1) 69-41-65-86  |
+--------------------------+------------------------------------+
|      ######      **                                           |
|     ##     #         Laboratoire de recherche en informatique |
|    ##       #   ##   Batiment 490                             |
|   ##       #   ##    Universite de Paris-Sud                  |
|  ##    ####   ##     91405 ORSAY Cedex                        |
| ######    ## ##      FRANCE                                   |
|######      ###                                                |
+---------------------------------------------------------------+
Technical Details
Message-ID: <199301261525.AA26111@lri.lri.fr>
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!ames!sun-barr!cs.utexas.edu!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!lri.FR!yb

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!ames!sun-barr!cs.utexas.edu!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!lri.FR!yb
From: yb@lri.FR
Newsgroups: gnu.g++.bug
Subject: badly generated operator new in template
Date: 26 Jan 1993 22:06:10 -0500
Organization: GNUs Not Usenet
Lines: 56
Sender: daemon@cis.ohio-state.edu
Approved: bug-g++@prep.ai.mit.edu
Distribution: gnu
Message-ID: <199301261525.AA26111@lri.lri.fr>