This is the mail archive of the gcc-patches@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]

egcs-19990714, returning NULL from operator new


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"


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