From b17c40be653fc91102da14682785dfa97ec0f9c0 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Tue, 14 Oct 2008 17:51:55 +0000 Subject: [PATCH] re PR c++/37650 (ICE with broken default template parameter) /cp 2008-10-14 Paolo Carlini PR c++/37650 * pt.c (push_template_decl_real): Check that current_template_parms is not null. (process_partial_specialization): Assert current_template_parms not null. /testsuite 2008-10-14 Paolo Carlini PR c++/37650 * g++.dg/template/crash83.C: New. From-SVN: r141115 --- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/pt.c | 13 +++++++++---- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/template/crash83.C | 5 +++++ 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/crash83.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1b38209a3a1..73a1656522d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2008-10-14 Paolo Carlini + + PR c++/37650 + * pt.c (push_template_decl_real): Check that current_template_parms + is not null. + (process_partial_specialization): Assert current_template_parms not + null. + 2008-10-13 Doug Evans * cp-tree.h (DECL_MAIN_P): Fix parentheses around expression. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 67b6dc68ab5..13a236101b5 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -3292,15 +3292,20 @@ process_partial_specialization (tree decl) tree maintmpl = CLASSTYPE_TI_TEMPLATE (type); tree specargs = CLASSTYPE_TI_ARGS (type); tree inner_args = INNERMOST_TEMPLATE_ARGS (specargs); - tree inner_parms = INNERMOST_TEMPLATE_PARMS (current_template_parms); tree main_inner_parms = DECL_INNERMOST_TEMPLATE_PARMS (maintmpl); + tree inner_parms; int nargs = TREE_VEC_LENGTH (inner_args); - int ntparms = TREE_VEC_LENGTH (inner_parms); + int ntparms; int i; int did_error_intro = 0; struct template_parm_data tpd; struct template_parm_data tpd2; + gcc_assert (current_template_parms); + + inner_parms = INNERMOST_TEMPLATE_PARMS (current_template_parms); + ntparms = TREE_VEC_LENGTH (inner_parms); + /* We check that each of the template parameters given in the partial specialization is used in the argument list to the specialization. For example: @@ -3749,8 +3754,8 @@ push_template_decl_real (tree decl, bool is_friend) [temp.mem]. */ bool member_template_p = false; - if (decl == error_mark_node) - return decl; + if (decl == error_mark_node || !current_template_parms) + return error_mark_node; /* See if this is a partial specialization. */ is_partial = (DECL_IMPLICIT_TYPEDEF_P (decl) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e4f3da8c6fe..8f3e7b4ae4f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-10-14 Paolo Carlini + + PR c++/37650 + * g++.dg/template/crash83.C: New. + 2008-10-14 Douglas Gregor PR c++/37553 diff --git a/gcc/testsuite/g++.dg/template/crash83.C b/gcc/testsuite/g++.dg/template/crash83.C new file mode 100644 index 00000000000..b83dd213971 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/crash83.C @@ -0,0 +1,5 @@ +// PR c++/37650 + +template struct A {}; + +template: > struct B {}; // { dg-error "explicit specialization|expected" } -- 2.30.2