From 6da06848ec8206c9824187019a9168b7aa38c94e Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 20 Nov 2007 07:38:48 +0100 Subject: [PATCH] re PR c++/28879 (ICE with VLA in template function) PR c++/28879 * tree.c (build_cplus_array_type_1): Don't pass any VLA types when processing_template_decl to build_array_type. * g++.dg/template/vla2.C: New test. From-SVN: r130309 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/tree.c | 8 ++++---- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/template/vla2.C | 20 ++++++++++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/vla2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d8e95c682618..b7c7661a9048 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2007-11-20 Jakub Jelinek + PR c++/28879 + * tree.c (build_cplus_array_type_1): Don't pass any VLA types + when processing_template_decl to build_array_type. + PR c++/33962 * pt.c (more_specialized_fn): Don't segfault if one or both argument list end with ellipsis. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 2a7cd3af747d..252195d3ca89 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -529,9 +529,9 @@ build_cplus_array_type_1 (tree elt_type, tree index_type) if (elt_type == error_mark_node || index_type == error_mark_node) return error_mark_node; - if (dependent_type_p (elt_type) - || (index_type - && value_dependent_expression_p (TYPE_MAX_VALUE (index_type)))) + if (processing_template_decl + && (dependent_type_p (elt_type) + || (index_type && !TREE_CONSTANT (TYPE_MAX_VALUE (index_type))))) { void **e; cplus_array_info cai; @@ -570,7 +570,7 @@ build_cplus_array_type_1 (tree elt_type, tree index_type) TYPE_CANONICAL (t) = build_cplus_array_type (TYPE_CANONICAL (elt_type), - index_type? TYPE_CANONICAL (index_type) : index_type); + index_type ? TYPE_CANONICAL (index_type) : index_type); else TYPE_CANONICAL (t) = t; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 585c7209b68c..cd4b067eaa33 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2007-11-20 Jakub Jelinek + PR c++/28879 + * g++.dg/template/vla2.C: New test. + PR c++/33962 * g++.dg/overload/template3.C: New test. diff --git a/gcc/testsuite/g++.dg/template/vla2.C b/gcc/testsuite/g++.dg/template/vla2.C new file mode 100644 index 000000000000..183f8fadc0ec --- /dev/null +++ b/gcc/testsuite/g++.dg/template/vla2.C @@ -0,0 +1,20 @@ +// PR c++/28879 +// { dg-do compile } +// { dg-options "" } + +struct A +{ + static int i; + int j; +}; + +template void foo () +{ + int x[A::i]; +//int y[A().j]; +} + +void bar () +{ + foo<6> (); +}