This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Error in g++ library, function ___builtin_vec_new


|> On Jan 28, 2000, f981500@FFZJ0LX0.bank.dresdner.net (James Kanze) wrote:

|> > I've encountered an error in the default implementation of
|> > ___builtin_vec_delete in the C++ library.  From disassembly, it appears

|> > that this function calls free to free the memory

|> Indeed.

|> > rather than operator delete, as is required by the standard.

|> I can't find this requirement in the standard.  The specification of
|> new[] and new[]nothrow do specify that they return their non-array new
|> counterparts, but the specification of delete[] and delete[]nothrow
|> just say they reclaim the memory allocated by the corresponding new[],
|> no mention to the non-array delete.

|> Am I missing anything?

Yes.  The standard requires (I'm not sure where, but the issue has often
been raised in the newsgroups) that memory allocated by operator new be
freed by operator delete.  The standard requires that the default
behavior of operator new[] is to call operator new, and it requires that
the default behavior of operator delete[] free the memory.  Since the
only legal way of freeing the memory is to call operator delete, I don't 
see how the standard can be interpreted as allowing anything else.

On the other hand, given how easy it is to simply say "the default
implementation must call operator delete", one does wonder why they
chose something more complicated.  Perhaps a defect report is in order.

From a practical point of usability: if you are developing software, and 
you don't have access to tools like Purify (which is far too expensive
for home development), you overload operator new and operator delete, so 
as to provide memory leak detection, etc.  The only exception I know of
is if you are using VC++ and DLL's -- VC++ gets very confused in such
cases, and generally will cause the program to crash.  Much like what
happened with g++, in fact:-).  (It's interesting to note that my code
worked with g++ 2.8.2, no doubt because it didn't have a
___builtin_vec_delete.)


--
James Kanze                         mailto:James.Kanze@gabi-soft.de
Conseils en informatique orientée objet/
                  Beratung in objekt orientierter Datenverarbeitung
Ziegelhüttenweg 17a, 60598 Frankfurt, Germany Tel. +49(069)63198627

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]