This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] Fix PR c++/27430: ICE on array of voids as template parameter
- From: Volker Reichelt <reichelt at igpm dot rwth-aachen dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 05 May 2006 14:01:21 +0200 (CEST)
- Subject: [patch] Fix PR c++/27430: ICE on array of voids as template parameter
The C++ frontend ICEs on the following code snippet:
template<void[]> struct A;
PR27430.cc:1: error: creating array of void
PR27430.cc:1: internal compiler error: tree check: expected class 'type',
have 'exceptional' (error_mark) in process_template_parm, at cp/pt.c:2354
Please submit a full bug report,
This is because process_template_parm cannot handle error_mark_node
as type of a non-type template parameter. We ICE calling TYPE_MAIN_VARIANT
for the error_mark_node.
The following patch fixes that by not calling TYPE_MAIN_VARIANT for the
error_mark_node and instead replacing it with a void_type_node. The latter
is already done for other invalid types. The patch also moves the sanity
checks to one place.
Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline?
Regards,
Volker
:ADDPATCH C++:
2006-05-05 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/27430
* pt.c (process_template_parm): Handle erroneous non-type parameters.
===================================================================
*** gcc/gcc/cp/pt.c Thu May 4 21:49:04 2006
--- gcc/gcc/cp/pt.c Thu May 4 22:10:10 2006
*************** process_template_parm (tree list, tree n
*** 2347,2364 ****
SET_DECL_TEMPLATE_PARM_P (parm);
! /* [temp.param]
! The top-level cv-qualifiers on the template-parameter are
! ignored when determining its type. */
! TREE_TYPE (parm) = TYPE_MAIN_VARIANT (TREE_TYPE (parm));
/* A template parameter is not modifiable. */
TREE_CONSTANT (parm) = 1;
TREE_INVARIANT (parm) = 1;
TREE_READONLY (parm) = 1;
- if (invalid_nontype_parm_type_p (TREE_TYPE (parm), 1))
- TREE_TYPE (parm) = void_type_node;
decl = build_decl (CONST_DECL, DECL_NAME (parm), TREE_TYPE (parm));
TREE_CONSTANT (decl) = 1;
TREE_INVARIANT (decl) = 1;
--- 2347,2369 ----
SET_DECL_TEMPLATE_PARM_P (parm);
! if (TREE_TYPE (parm) == error_mark_node)
! TREE_TYPE (parm) = void_type_node;
! else
! {
! /* [temp.param]
! The top-level cv-qualifiers on the template-parameter are
! ignored when determining its type. */
! TREE_TYPE (parm) = TYPE_MAIN_VARIANT (TREE_TYPE (parm));
! if (invalid_nontype_parm_type_p (TREE_TYPE (parm), 1))
! TREE_TYPE (parm) = void_type_node;
! }
/* A template parameter is not modifiable. */
TREE_CONSTANT (parm) = 1;
TREE_INVARIANT (parm) = 1;
TREE_READONLY (parm) = 1;
decl = build_decl (CONST_DECL, DECL_NAME (parm), TREE_TYPE (parm));
TREE_CONSTANT (decl) = 1;
TREE_INVARIANT (decl) = 1;
===================================================================
2006-05-05 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/27430
* g++.dg/template/void1.C: New test.
===================================================================
--- gcc/gcc/testsuite/g++.dg/template/void1.C 2003-09-23 19:59:22 +0200
+++ gcc/gcc/testsuite/g++.dg/template/void1.C 2006-05-04 22:15:21 +0200
@@ -0,0 +1,4 @@
+// PR c++/27430
+// { dg-do compile }
+
+template<void[]> struct A; // { dg-error "array of void" }
===================================================================