From 2a50edcd0f5cca974fe82b27a1b109618afa1a05 Mon Sep 17 00:00:00 2001 From: Volker Reichelt Date: Mon, 17 Jul 2006 04:42:24 +0000 Subject: [PATCH] re PR c++/28250 (ICE with invalid catch) PR c++/28250 * name-lookup.c (pushdecl_maybe_friend): Return early on error_mark_node. * except.c (expand_start_catch_block): Use error_mark_node instead of NULL_TREE for invalid decls. * parser.c (cp_parser_exception_declaration): Return error_mark_node on invalid catch parameter. Simplify. * g++.dg/eh/catch1.C: New test. * g++.dg/eh/catch2.C: New test. From-SVN: r115516 --- gcc/cp/ChangeLog | 10 ++++++++++ gcc/cp/except.c | 4 ++-- gcc/cp/name-lookup.c | 3 +++ gcc/cp/parser.c | 13 +++---------- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/eh/catch1.C | 8 ++++++++ gcc/testsuite/g++.dg/eh/catch2.C | 9 +++++++++ 7 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/g++.dg/eh/catch1.C create mode 100644 gcc/testsuite/g++.dg/eh/catch2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d1eb30fea24..821df2bde78 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,13 @@ +2006-07-17 Volker Reichelt + + PR c++/28250 + * name-lookup.c (pushdecl_maybe_friend): Return early on + error_mark_node. + * except.c (expand_start_catch_block): Use error_mark_node instead + of NULL_TREE for invalid decls. + * parser.c (cp_parser_exception_declaration): Return error_mark_node + on invalid catch parameter. Simplify. + 2006-07-16 Jakub Jelinek PR c++/28370 diff --git a/gcc/cp/except.c b/gcc/cp/except.c index a02fc2f5533..17166d92af0 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -412,7 +412,7 @@ expand_start_catch_block (tree decl) /* Make sure this declaration is reasonable. */ if (decl && !complete_ptr_ref_or_void_ptr_p (TREE_TYPE (decl), NULL_TREE)) - decl = NULL_TREE; + decl = error_mark_node; if (decl) type = prepare_eh_type (TREE_TYPE (decl)); @@ -438,7 +438,7 @@ expand_start_catch_block (tree decl) /* If there's no decl at all, then all we need to do is make sure to tell the runtime that we've begun handling the exception. */ - if (decl == NULL) + if (decl == NULL || decl == error_mark_node) finish_expr_stmt (do_begin_catch ()); /* If the C++ object needs constructing, we need to do that before diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 43d74dc968e..7cc2fee5329 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -569,6 +569,9 @@ pushdecl_maybe_friend (tree x, bool is_friend) timevar_push (TV_NAME_LOOKUP); + if (x == error_mark_node) + POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node); + need_new_binding = 1; if (DECL_TEMPLATE_PARM_P (x)) diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index a2d41f164a7..c4224019da7 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -14343,7 +14343,6 @@ cp_parser_handler (cp_parser* parser) static tree cp_parser_exception_declaration (cp_parser* parser) { - tree decl; cp_decl_specifier_seq type_specifiers; cp_declarator *declarator; const char *saved_message; @@ -14376,16 +14375,10 @@ cp_parser_exception_declaration (cp_parser* parser) /* Restore the saved message. */ parser->type_definition_forbidden_message = saved_message; - if (type_specifiers.any_specifiers_p) - { - decl = grokdeclarator (declarator, &type_specifiers, CATCHPARM, 1, NULL); - if (decl == NULL_TREE) - error ("invalid catch parameter"); - } - else - decl = NULL_TREE; + if (!type_specifiers.any_specifiers_p) + return error_mark_node; - return decl; + return grokdeclarator (declarator, &type_specifiers, CATCHPARM, 1, NULL); } /* Parse a throw-expression. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 98eaa25b066..8b6cf37bd73 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2006-07-17 Volker Reichelt + + PR c++/28250 + * g++.dg/eh/catch1.C: New test. + * g++.dg/eh/catch2.C: New test. + 2006-07-16 Jakub Jelinek PR c++/28370 diff --git a/gcc/testsuite/g++.dg/eh/catch1.C b/gcc/testsuite/g++.dg/eh/catch1.C new file mode 100644 index 00000000000..730218011ff --- /dev/null +++ b/gcc/testsuite/g++.dg/eh/catch1.C @@ -0,0 +1,8 @@ +// PR c++/28250 +// { dg-do compile } + +template void foo() +{ + try {} + catch (int(0)) {} // { dg-error "before" } +} diff --git a/gcc/testsuite/g++.dg/eh/catch2.C b/gcc/testsuite/g++.dg/eh/catch2.C new file mode 100644 index 00000000000..33db946490a --- /dev/null +++ b/gcc/testsuite/g++.dg/eh/catch2.C @@ -0,0 +1,9 @@ +// PR c++/28250 +// { dg-do compile } + +void foo() +{ + try {} + catch () {} // { dg-error "before" } + catch (...) {} +}