From: Mark Mitchell Date: Wed, 10 Sep 1997 02:28:20 +0000 (+0000) Subject: error.c (dump_decl): Avoid crashing when presented with a uninitialized constant... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=03555413998ae48323618a55b7c7decca29a1594;p=gcc.git error.c (dump_decl): Avoid crashing when presented with a uninitialized constant... Tue Sep 9 17:57:25 1997 Mark Mitchell * error.c (dump_decl): Avoid crashing when presented with a uninitialized constant, as can occur with a template parameter. From-SVN: r15208 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 39b5e1cebcc..c9eabf990d8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +Tue Sep 9 17:57:25 1997 Mark Mitchell + + * error.c (dump_decl): Avoid crashing when presented with a + uninitialized constant, as can occur with a template parameter. + 1997-09-09 Brendan Kehoe * typeck.c (build_indirect_ref): Heed FLAG_VOLATILE similar to diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 847bfa22495..4f4c5996bb7 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -782,10 +782,13 @@ dump_decl (t, v) case CONST_DECL: if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE) - || TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_CONST_PARM) + || (DECL_INITIAL (t) && + TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_CONST_PARM)) goto general; - else + else if (DECL_INITIAL (t)) dump_expr (DECL_INITIAL (t), 0); + else + OB_PUTS ("enumerator"); break; case USING_DECL: @@ -1363,29 +1366,33 @@ dump_expr (t, nop) } case TEMPLATE_CONST_PARM: - if (current_template_parms) - { - int i; - int l = list_length (current_template_parms); - tree parms = current_template_parms; - tree r; - - for (i = 0; i < l - TEMPLATE_CONST_LEVEL (t); ++i) - { - parms = TREE_CHAIN (parms); - my_friendly_assert (parms != NULL_TREE, 0); - } + { + int l = current_template_parms ? + list_length (current_template_parms) : 0; - r = TREE_VEC_ELT (TREE_VALUE (parms), - TEMPLATE_CONST_IDX (t)); - dump_decl (TREE_VALUE (r), -1); - } - else - { - OB_PUTS (""); - } + if (l >= TEMPLATE_CONST_LEVEL (t)) + { + int i; + tree parms = current_template_parms; + tree r; + + for (i = 0; i < l - TEMPLATE_CONST_LEVEL (t); ++i) + { + parms = TREE_CHAIN (parms); + my_friendly_assert (parms != NULL_TREE, 0); + } + + r = TREE_VEC_ELT (TREE_VALUE (parms), + TEMPLATE_CONST_IDX (t)); + dump_decl (TREE_VALUE (r), -1); + } + else + { + OB_PUTS (""); + } + } break; case IDENTIFIER_NODE: