This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
egcs-19990714, returning NULL from operator new
- To: egcs-patches at egcs dot cygnus dot com
- Subject: egcs-19990714, returning NULL from operator new
- From: "Carlos O'Ryan" <coryan at cs dot wustl dot edu>
- Date: Fri, 16 Jul 1999 11:04:20 -0500 (CDT)
- CC: mrs at wrs dot com, martin at mira dot isdn dot cs dot tu-berlin dot de
Hi,
This fixes a pesky error message about not returning NULL
from a new operator. IMHO the message should not read "should throw an
exception" if exceptions are enabled and should be disabled if the
-fcheck-new flag is present [thanks to Mike Stump for that idea]
---------------- cut here ----------------
--- egcs-19990714/gcc/cp/typeck.c.orig Thu Jul 15 13:50:39 1999
+++ egcs-19990714/gcc/cp/typeck.c Fri Jul 16 10:01:00 1999
@@ -39,6 +39,8 @@
#include "expr.h"
#include "toplev.h"
+extern int flag_check_new; // For -fcheck-new
+
static tree convert_for_assignment PROTO((tree, tree, const char *, tree,
int));
static tree pointer_int_sum PROTO((enum tree_code, tree, tree));
@@ -7353,8 +7355,12 @@
|| DECL_NAME (current_function_decl) == ansi_opname[(int) VEC_NEW_EXPR])
&& !TYPE_NOTHROW_P (TREE_TYPE (current_function_decl))
&& null_ptr_cst_p (retval))
+ {
+ if (doing_eh ())
cp_pedwarn ("operator new should throw an exception, not return NULL");
-
+ else if (!flag_check_new)
+ cp_pedwarn ("operator new should not return NULL, use -fcheck-new");
+ }
if (retval == NULL_TREE)
{
/* A non-named return value does not count. */
---------------- cut here ----------------
--
Carlos O'Ryan (coryan@cs.wustl.edu)
#include <std.disclaimer>
#include <cute.quote> // "Speak softly and carry a megawatt laser"