dummy operator new() warnings

Chris Seawood clsATseawood.org
Wed Sep 15 13:00:00 GMT 1999


In Mozilla, there are a number of classes that have dummy operator new
functions.  Prior to the gcc 2.95 release, they seemed to compile fine if
we just returned 0.  With gcc 2.95.1, we now get this warning if we try
to return 0 from a operator new() (regardless of what -W options are
given):
 warning: operator new should throw an exception, not return NULL

The warning is fairly straight forward but we have another problem.  For
portability reasons, Mozilla doesn't use exceptions (or at least, that's
what their guidelines say).  Would it be possible to turn off that warning
if the code is being compiled with -fno-exceptions (as Mozilla usually
is)?  Or have a switch -Wno-new-exceptions or something?

The other option would be to be not to return anything which generates a
warning when compiled with -Wall (-Wreturn-type actually) under gcc
2.95+ but compiles cleanly without it.  I'm not sure what gcc < 2.95 does
in this scenario.

- cls



More information about the Gcc-bugs mailing list