This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] PR c++/30534: ICE with invalid template argument
- From: Volker Reichelt <v dot reichelt at netcologne dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 4 Mar 2007 22:30:53 +0100 (CET)
- Subject: [PATCH] PR c++/30534: ICE with invalid template argument
The following code snippet triggers an ICE on mainline:
template<bool> struct A;
template<int> void foo()
{
A<__builtin_constant_p(.)> a;
}
bug.cc: In function 'void foo()':
bug.cc:5: internal compiler error: tree check: expected class 'type', have
'exceptional' (error_mark) in
any_template_arguments_need_structural_equality_p, at cp/pt.c:13258
Please submit a full bug report, [etc.]
The problem is that any_template_arguments_need_structural_equality_p
doesn't check the template arguments for error_mark_node. (It does
check for an invalid template argument list, though.)
The patch below fixes the ICE by adding such a check.
Bootstrapped and regtested on i686-pc-linux-gnu.
Ok for mainline?
Regards,
Volker
:ADDPATCH C++:
2007-03-04 Volker Reichelt <reichelt@netcologne.de>
PR c++/30534
* pt.c (any_template_arguments_need_structural_equality_p):
Robustify.
===================================================================
--- gcc/gcc/cp/pt.c 2007-02-11 13:01:42 +0100
+++ gcc/gcc/cp/pt.c 2007-02-11 13:00:35 +0100
@@ -13131,7 +13131,9 @@ any_template_arguments_need_structural_e
for (j = 0; j < TREE_VEC_LENGTH (level); ++j)
{
tree arg = TREE_VEC_ELT (level, j);
- if (TREE_CODE (arg) == TEMPLATE_DECL
+ if (error_operand_p (arg))
+ return true;
+ else if (TREE_CODE (arg) == TEMPLATE_DECL
|| TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM)
continue;
else if (TYPE_P (arg) && TYPE_STRUCTURAL_EQUALITY_P (arg))
===================================================================
2007-03-04 Volker Reichelt <reichelt@netcologne.de>
PR c++/30534
* g++.dg/template/arg5.C: New test.
===================================================================
--- gcc/gcc/testsuite/g++.dg/template/arg5.C 2003-09-23 19:59:22 +0200
+++ gcc/gcc/testsuite/g++.dg/template/arg5.C 2007-02-11 23:03:06 +0100
@@ -0,0 +1,9 @@
+// PR c++/30534
+// { dg-do compile }
+
+template<bool> struct A;
+
+template<int> void foo()
+{
+ A<__builtin_constant_p(.)> a; // { dg-error "template argument" }
+}
===================================================================