[patch] Fix PR c++/22233, ICE on invalid number of template parameters
Volker Reichelt
reichelt@igpm.rwth-aachen.de
Wed Aug 17 20:20:00 GMT 2005
Consider the following invalid testcase:
template<int> struct A
{
A();
};
template<int N, char> A<N>::A() {}
A<0> a;
After a suitable error message
param1.C:6: error: got 2 template parameters for 'A<<anonymous> >::A()'
param1.C:6: error: but 1 required
we get an ICE when instantiating A:
param1.C: In instantiation of 'A<0>':
param1.C:8: instantiated from here
param1.C:6: internal compiler error: tree check: accessed elt 2 of tree_vec with 1 elts in tsubst, at cp/pt.c:7071
Btw, this happens with any member function, not just a constructor.
The patch fixes that by returning an error_mark_node from
push_template_decl_real when the non-matching template arguments
are encountered. This prevents that the invalid declaration is
considered at instantiation time.
Bootstrapped and regtested on i686-pc-linux-gnu.
Ok for mainline, 4.0 branch and 3.4 branch (since this is a regression)?
Regards,
Volker
2005-08-17 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/22233
* pt.c (push_template_decl_real): Return error_mark_node if the
number of template parameters does not match previous definition.
===================================================================
--- gcc/gcc/cp/pt.c 12 Aug 2005 09:23:43 -0000 1.1022
+++ gcc/gcc/cp/pt.c 17 Aug 2005 11:11:45 -0000
@@ -3109,6 +3109,7 @@ push_template_decl_real (tree decl, int
error ("got %d template parameters for %q#T",
TREE_VEC_LENGTH (a), current);
error (" but %d required", TREE_VEC_LENGTH (t));
+ return error_mark_node;
}
/* Perhaps we should also check that the parms are used in the
===================================================================
2005-08-17 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/22233
* g++.dg/template/param1.C: New test.
===================================================================
--- gcc/gcc/testsuite/g++.dg/template/param1.C 2003-09-23 19:59:22 +0200
+++ gcc/gcc/testsuite/g++.dg/template/param1.C 2005-08-17 19:54:38 +0200
@@ -0,0 +1,12 @@
+// PR c++/22233
+// Origin: Volker Reichelt <reichelt@igpm.rwth-aachen.de>
+// { dg-do compile }
+
+template<int> struct A
+{
+ A();
+};
+
+template<int N, char> A<N>::A() {} // { dg-error "got 2|but 1 required" }
+
+A<0> a;
===================================================================
More information about the Gcc-patches
mailing list