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]
Other format: [Raw text]

PR C++/36406 disable overloaded delete as a template


Hi Jason.  Hi folks.

We are ICEing on the following invalid code, because
build_op_delete_call() is getting confused while finding a suitable
delete for the new.

	struct A
	{
	  A();
	  void* operator new(__SIZE_TYPE__, int = 0);
	  template<int> void operator delete(void*, int);
	};

	A* p = new A;

I suggest disabling overloaded operator deletes when the delete is a
template.  Jason, you mentioned the standard doesn't explicitly prohibit
it, but I can't seem to google up any code that actually does this.

The following patch fixes the PR with no regressions.  If we *must* allow
overloaded deletes as a template, can someone provide me with a valid
code snippet of a use?

OK?

testsuite/
	* g++.dg/torture/pr36406.C: New.
cp/
	PR c++/36406
	* call.c (build_op_delete_call): Error when trying to use an
	overloaded delete as a template on a placement call.

Index: testsuite/g++.dg/torture/pr36406.C
===================================================================
--- testsuite/g++.dg/torture/pr36406.C	(revision 0)
+++ testsuite/g++.dg/torture/pr36406.C	(revision 0)
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+
+struct A
+{
+  A();
+  void* operator new(__SIZE_TYPE__, int = 0);
+  template<int> void operator delete(void*, int);
+};
+
+A* p = new A; /* { dg-error "no suitable 'operator delete'" } */
Index: cp/call.c
===================================================================
--- cp/call.c	(revision 138717)
+++ cp/call.c	(working copy)
@@ -4376,6 +4376,12 @@ build_op_delete_call (enum tree_code cod
 	  int nargs = call_expr_nargs (placement);
 	  tree *argarray = (tree *) alloca (nargs * sizeof (tree));
 	  int i;
+
+	  /* An overload delete as a template?  That can't be
+	     right.  */
+	  if (TREE_CODE (fn) == TEMPLATE_DECL)
+	    goto no_operator_found;
+
 	  argarray[0] = addr;
 	  for (i = 1; i < nargs; i++)
 	    argarray[i] = CALL_EXPR_ARG (placement, i);
@@ -4407,6 +4413,7 @@ build_op_delete_call (enum tree_code cod
       return NULL_TREE;
     }
 
+ no_operator_found:
   error ("no suitable %<operator %s%> for %qT",
 	 operator_name_info[(int)code].name, type);
   return error_mark_node;


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