This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 15890
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 19 Aug 2004 13:20:07 -0700
- Subject: C++ PATCH: PR 15890
- Reply-to: mark at codesourcery dot com
This patch fixes an ICE-on-invalid regression: you may not declare a
one-argument allocation function to be a template.
Tested in i686-pc-linux-gnu, applied on the mainline and on the
branch.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
2004-08-19 Mark Mitchell <mark@codesourcery.com>
PR c++/15890
* pt.c (push_template_decl_real): Disallow template allocation
functions with fewer than two parameters.
2004-08-19 Mark Mitchell <mark@codesourcery.com>
PR c++/15890
* g++.dg/template/delete1.C: New test.
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.909
diff -c -5 -p -r1.909 pt.c
*** cp/pt.c 19 Aug 2004 05:08:09 -0000 1.909
--- cp/pt.c 19 Aug 2004 20:12:13 -0000
*************** push_template_decl_real (tree decl, int
*** 2873,2895 ****
if (current_lang_name == lang_name_c)
error ("template with C linkage");
else if (TREE_CODE (decl) == TYPE_DECL
&& ANON_AGGRNAME_P (DECL_NAME (decl)))
error ("template class without a name");
! else if (TREE_CODE (decl) == FUNCTION_DECL
! && DECL_DESTRUCTOR_P (decl))
{
! /* [temp.mem]
!
! A destructor shall not be a member template. */
! error ("destructor `%D' declared as member template", decl);
! return error_mark_node;
}
else if ((DECL_IMPLICIT_TYPEDEF_P (decl)
&& CLASS_TYPE_P (TREE_TYPE (decl)))
! || (TREE_CODE (decl) == VAR_DECL && ctx && CLASS_TYPE_P (ctx))
! || TREE_CODE (decl) == FUNCTION_DECL)
/* OK */;
else
{
error ("template declaration of `%#D'", decl);
return error_mark_node;
--- 2873,2911 ----
if (current_lang_name == lang_name_c)
error ("template with C linkage");
else if (TREE_CODE (decl) == TYPE_DECL
&& ANON_AGGRNAME_P (DECL_NAME (decl)))
error ("template class without a name");
! else if (TREE_CODE (decl) == FUNCTION_DECL)
{
! if (DECL_DESTRUCTOR_P (decl))
! {
! /* [temp.mem]
!
! A destructor shall not be a member template. */
! error ("destructor `%D' declared as member template", decl);
! return error_mark_node;
! }
! if (NEW_DELETE_OPNAME_P (DECL_NAME (decl))
! && (!TYPE_ARG_TYPES (TREE_TYPE (decl))
! || TYPE_ARG_TYPES (TREE_TYPE (decl)) == void_list_node
! || !TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl)))
! || (TREE_CHAIN (TYPE_ARG_TYPES ((TREE_TYPE (decl))))
! == void_list_node)))
! {
! /* [basic.stc.dynamic.allocation]
!
! An allocation function can be a function
! template. ... Template allocation functions shall
! have two or more parameters. */
! error ("invalid template declaration of `%D'", decl);
! return decl;
! }
}
else if ((DECL_IMPLICIT_TYPEDEF_P (decl)
&& CLASS_TYPE_P (TREE_TYPE (decl)))
! || (TREE_CODE (decl) == VAR_DECL && ctx && CLASS_TYPE_P (ctx)))
/* OK */;
else
{
error ("template declaration of `%#D'", decl);
return error_mark_node;
Index: testsuite/g++.dg/template/delete1.C
===================================================================
RCS file: testsuite/g++.dg/template/delete1.C
diff -N testsuite/g++.dg/template/delete1.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/delete1.C 19 Aug 2004 20:12:14 -0000
***************
*** 0 ****
--- 1,14 ----
+ // PR c++/15890
+
+ template < typename T >
+ void operator delete ( void* raw ) { // { dg-error "" }
+ delete raw;
+ }
+
+ class A { };
+
+ int main() {
+ A* a = new A;
+ delete a;
+ }
+