This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for bogus delete handling
- To: egcs-patches at egcs dot cygnus dot com
- Subject: C++ PATCH for bogus delete handling
- From: mark at codesourcery dot com
- Date: Wed, 16 Jun 1999 11:28:58 -0700
- Organization: CodeSourcery, LLC
Here's a patch to remove some utterly bizarre code that messed up the
way we handled calls to operator delete.
Applied on branch and mainline.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
1999-06-16 Mark Mitchell <mark@codesourcery.com>
* call.c (build_method_call): Remove bogus code for two-argument
delete.
* init.c (build_new_1): Expand on comment, and remove dead code.
Index: testsuite/g++.old-deja/g++.other/delete6.C
===================================================================
RCS file: delete6.C
diff -N delete6.C
--- /dev/null Sat Dec 5 20:30:03 1998
+++ delete6.C Wed Jun 16 10:58:14 1999
@@ -0,0 +1,27 @@
+// Origin: Alexander Schiemann (aschiem@count.math.uni-sb.de)
+
+int i;
+
+struct B{};
+
+struct A{
+
+ static void* operator new(unsigned int)
+ {return &i;}
+
+ inline static void operator delete(void*p);
+
+ static void operator delete(void*, const B&){}
+
+};
+
+
+inline void A::operator delete(void*p)
+{A::operator delete(p,B());}
+
+
+int main()
+{A *ap=new A;
+delete ap;}
+
+
Index: cp/call.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/call.c,v
retrieving revision 1.148
diff -u -p -r1.148 call.c
--- call.c 1999/06/14 02:44:17 1.148
+++ call.c 1999/06/16 17:58:16
@@ -474,29 +474,6 @@ build_method_call (instance, name, parms
return build_min_nt (METHOD_CALL_EXPR, name, instance, parms, NULL_TREE);
}
- /* This is the logic that magically deletes the second argument to
- operator delete, if it is not needed. */
- if (name == ansi_opname[(int) DELETE_EXPR] && list_length (parms)==2)
- {
- tree save_last = TREE_CHAIN (parms);
-
- /* get rid of unneeded argument */
- TREE_CHAIN (parms) = NULL_TREE;
- if (build_method_call (instance, name, parms, basetype_path,
- (LOOKUP_SPECULATIVELY|flags) & ~LOOKUP_COMPLAIN))
- {
- /* If it finds a match, return it. */
- return build_method_call (instance, name, parms, basetype_path, flags);
- }
- /* If it doesn't work, two argument delete must work */
- TREE_CHAIN (parms) = save_last;
- }
- /* We already know whether it's needed or not for vec delete. */
- else if (name == ansi_opname[(int) VEC_DELETE_EXPR]
- && TYPE_LANG_SPECIFIC (TREE_TYPE (instance))
- && ! TYPE_VEC_DELETE_TAKES_SIZE (TREE_TYPE (instance)))
- TREE_CHAIN (parms) = NULL_TREE;
-
if (TREE_CODE (name) == BIT_NOT_EXPR)
{
if (parms)
Index: cp/init.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/init.c,v
retrieving revision 1.108
diff -u -p -r1.108 init.c
--- init.c 1999/06/16 10:15:34 1.108
+++ init.c 1999/06/16 17:58:30
@@ -2191,21 +2191,21 @@ build_new_1 (exp)
signature_error (NULL_TREE, true_type);
return error_mark_node;
}
+
+ /* When we allocate an array, and the corresponding deallocation
+ function takes a second argument of type size_t, and that's the
+ "usual deallocation function", we allocate some extra space at
+ the beginning of the array to store the size of the array.
-#if 1
- /* Get a little extra space to store a couple of things before the new'ed
- array, if this isn't the default placement new. */
+ Well, that's what we should do. For backwards compatibility, we
+ have to do this whenever there's a two-argument array-delete
+ operator.
+ FIXME: For -fnew-abi, we don't have to maintain backwards
+ compatibility and we should fix this. */
use_cookie = (has_array && TYPE_VEC_NEW_USES_COOKIE (true_type)
&& ! (placement && ! TREE_CHAIN (placement)
&& TREE_TYPE (TREE_VALUE (placement)) == ptr_type_node));
-#else
- /* Get a little extra space to store a couple of things before the new'ed
- array, if this is either non-placement new or new (nothrow). */
-
- use_cookie = (has_array && TYPE_VEC_NEW_USES_COOKIE (true_type)
- && (! placement || nothrow));
-#endif
if (use_cookie)
{