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: static inline operator generates an external symbol


> 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


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