[patch] Fix PR c++/27559: ICE on templated operator new

Volker Reichelt reichelt@igpm.rwth-aachen.de
Fri May 12 04:36:00 GMT 2006


The following invalid testcase ICEs on mainline:

  struct A
  {
    template<typename T>
    static void* operator new(T) {}
  };

bug.cc:4: error: 'operator new' takes type 'size_t' ('unsigned int') as first parameter
bug.cc:4: error: invalid template declaration of 'static void* A::operator new(unsigned int)'
bug.cc:4: error: invalid member template declaration 'static void* A::operator new(unsigned int)'
bug.cc: In static member function 'static void* A::operator new(unsigned int)':
bug.cc:4: internal compiler error: in dependent_type_p, at cp/pt.c:12372
Please submit a full bug report, [etc.]

The ICE happens because the operator new is treated as a non-template,
but its first argument is still marked as a dependent type. The attached
patch tackles this problem earlier (before dependent_type_p is called at
all): Instead of returning the broken decl from push_template_decl_real
it returns an error_mark_node.

Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline?

Regards,
Volker

:ADDPATCH C++:


2006-05-11  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/27559
	* pt.c (push_template_decl_real): Return error_mark_node instead
	of broken decl.

===================================================================
--- gcc/gcc/cp/pt.c	(revision 113691)
+++ gcc/gcc/cp/pt.c	(working copy)
@@ -3009,7 +3009,7 @@ push_template_decl_real (tree decl, bool is_friend)
 		 template. ... Template allocation functions shall
 		 have two or more parameters.  */
 	      error ("invalid template declaration of %qD", decl);
-	      return decl;
+	      return error_mark_node;
 	    }
 	}
       else if (DECL_IMPLICIT_TYPEDEF_P (decl)
===================================================================

2006-05-11  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/27559
	* g++.dg/template/new4.C: New test.

===================================================================
--- gcc/gcc/testsuite/g++.dg/template/new4.C	2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/g++.dg/template/new4.C	2006-05-11 13:56:18 +0200
@@ -0,0 +1,8 @@
+// PR c++/27559
+// { dg-do compile }
+
+struct A
+{
+  template<typename T>
+  static void* operator new(T) {} // { dg-error "first parameter|invalid template" }
+};
===================================================================




More information about the Gcc-patches mailing list