This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: egcs-19990714, returning NULL from operator new
- To: "Carlos O'Ryan" <coryan at cs dot wustl dot edu>
- Subject: Re: egcs-19990714, returning NULL from operator new
- From: Jason Merrill <jason at redhat dot com>
- Date: 30 Jun 2000 19:22:16 -0400
- Cc: gcc-patches at gcc dot gnu dot org
- References: <14223.21130.115567.663761@macarena.cs.wustl.edu>
I applied this patch:
2000-06-24 Carlos O'Ryan <coryan@cs.wustl.edu>
Jason Merrill <jason@redhat.com>
* typeck.c (check_return_expr): Don't complain about returning
NULL from operator new if -fcheck-new.
* cp-tree.h: Declare flag_check_new here.
* init.c: Not here.
*** cp-tree.h.~1~ Fri Jun 30 04:02:16 2000
--- cp-tree.h Fri Jun 30 04:02:19 2000
*************** extern int flag_enforce_eh_specs;
*** 1225,1230 ****
--- 1225,1235 ----
extern int flag_access_control;
+ /* Nonzero if we want to check the return value of new and avoid calling
+ constructors if it is a null pointer. */
+
+ extern int flag_check_new;
+
/* If this variable is defined to a non-NULL value, it will be called
after the file has been completely parsed. The argument will be
the GLOBAL_NAMESPACE. */
*** init.c.~1~ Fri Jun 30 04:02:16 2000
--- init.c Fri Jun 30 04:02:19 2000
*************** build_builtin_delete_call (addr)
*** 1975,1982 ****
PLACEMENT is the `placement' list for user-defined operator new (). */
- extern int flag_check_new;
-
tree
build_new (placement, decl, init, use_global_new)
tree placement;
--- 1975,1980 ----
*** typeck.c.~1~ Fri Jun 30 04:02:16 2000
--- typeck.c Fri Jun 30 04:02:19 2000
*************** check_return_expr (retval)
*** 6844,6851 ****
if ((DECL_OVERLOADED_OPERATOR_P (current_function_decl) == NEW_EXPR
|| DECL_OVERLOADED_OPERATOR_P (current_function_decl) == VEC_NEW_EXPR)
&& !TYPE_NOTHROW_P (TREE_TYPE (current_function_decl))
&& null_ptr_cst_p (retval))
! cp_warning ("`operator new' should throw an exception, not return NULL");
/* Effective C++ rule 15. See also start_function. */
if (warn_ecpp
--- 6844,6852 ----
if ((DECL_OVERLOADED_OPERATOR_P (current_function_decl) == NEW_EXPR
|| DECL_OVERLOADED_OPERATOR_P (current_function_decl) == VEC_NEW_EXPR)
&& !TYPE_NOTHROW_P (TREE_TYPE (current_function_decl))
+ && ! flag_check_new
&& null_ptr_cst_p (retval))
! cp_warning ("`operator new' must not return NULL unless it is declared `throw()' (or -fcheck-new is in effect)");
/* Effective C++ rule 15. See also start_function. */
if (warn_ecpp