static inline operator generates an external symbol

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Fri Jan 14 13:57:00 GMT 2000


> I'm in a situation where I need to overload the standard new/delete
> operators for a portion of my code.  I defined them as static inline
> inside an include file and everything compiles.  When I go to link,
> however, I get multiple definitions of __builtin_new, etc.  Those
> static inline operators are being exported.  Is this a bug?

Thanks for your bug report. This is a bug, both in your code, and in
gcc. The bug in your code is that operator new is declared extern, and
later declared static. The bug in g++ is that it does not detect this
incorrect redeclaration.

> Is there a better way to do this?  There are too many object types
> to overload for each of them.

You could declare the operator new in a base class only. Other than
that, there is no alternative. C++ does not support file-local
allocation mechanisms.

Regards,
Martin



More information about the Gcc-bugs mailing list