From 84019f237c3ec98ccd3bd7044f45d7b8e412a334 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Thu, 15 Jun 2006 03:40:42 +0000 Subject: [PATCH] re PR c++/27648 (ICE on attribute on pointers in static_cast) PR c++/26748 * parser.c (cp_parser_declarator): Robustify. PR c++/26748 * g++.dg/ext/attrib22.C: New test. From-SVN: r114667 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/parser.c | 41 +++++++++++++---------------- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/ext/attrib22.C | 6 +++++ 4 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/attrib22.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index afd2f7af5b7..be561f9bbc8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2006-06-14 Mark Mitchell + PR c++/26748 + * parser.c (cp_parser_declarator): Robustify. + PR c++/26559 * pt.c (tsubst_expr): Use finish_omp_atomic. (value_dependent_expression_p): All CALL_EXPRs are dependent. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index eaebe191c54..df175fa21ae 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -3374,12 +3374,12 @@ cp_parser_unqualified_id (cp_parser* parser, qualifying_scope = parser->qualifying_scope; /* If the name is of the form "X::~X" it's OK. */ + token = cp_lexer_peek_token (parser->lexer); if (scope && TYPE_P (scope) - && cp_lexer_next_token_is (parser->lexer, CPP_NAME) + && token->type == CPP_NAME && (cp_lexer_peek_nth_token (parser->lexer, 2)->type == CPP_OPEN_PAREN) - && (cp_lexer_peek_token (parser->lexer)->value - == TYPE_IDENTIFIER (scope))) + && constructor_name_p (token->value, scope)) { cp_lexer_consume_token (parser->lexer); return build_nt (BIT_NOT_EXPR, scope); @@ -3550,20 +3550,6 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser, cp_token_position start = 0; cp_token *token; - /* If the next token corresponds to a nested name specifier, there - is no need to reparse it. However, if CHECK_DEPENDENCY_P is - false, it may have been true before, in which case something - like `A::B::C' may have resulted in a nested-name-specifier - of `A::', where it should now be `A::B::'. So, when - CHECK_DEPENDENCY_P is false, we have to fall through into the - main loop. */ - if (check_dependency_p - && cp_lexer_next_token_is (parser->lexer, CPP_NESTED_NAME_SPECIFIER)) - { - cp_parser_pre_parsed_nested_name_specifier (parser); - return parser->scope; - } - /* Remember where the nested-name-specifier starts. */ if (cp_parser_uncommitted_to_tentative_parse_p (parser)) { @@ -3663,6 +3649,8 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser, class-or-namespace-name. */ parser->scope = old_scope; parser->qualifying_scope = saved_qualifying_scope; + if (cp_parser_uncommitted_to_tentative_parse_p (parser)) + break; /* If the next token is an identifier, and the one after that is a `::', then any valid interpretation would have found a class-or-namespace-name. */ @@ -8797,10 +8785,19 @@ cp_parser_template_id (cp_parser *parser, template_id = build_min_nt (TEMPLATE_ID_EXPR, template, arguments); else if (DECL_CLASS_TEMPLATE_P (template) || DECL_TEMPLATE_TEMPLATE_PARM_P (template)) - template_id - = finish_template_type (template, arguments, - cp_lexer_next_token_is (parser->lexer, - CPP_SCOPE)); + { + bool entering_scope; + /* In "template ... A::", A is the abstract A + template (rather than some instantiation thereof) only if + is not nested within some other construct. For example, in + "template void f(T) { A::", A is just an + instantiation of A. */ + entering_scope = (template_parm_scope_p () + && cp_lexer_next_token_is (parser->lexer, + CPP_SCOPE)); + template_id + = finish_template_type (template, arguments, entering_scope); + } else { /* If it's not a class-template or a template-template, it should be @@ -11283,7 +11280,7 @@ cp_parser_declarator (cp_parser* parser, member_p); } - if (attributes && declarator != cp_error_declarator) + if (attributes && declarator && declarator != cp_error_declarator) declarator->attributes = attributes; return declarator; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6615324667b..7565051541e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2006-06-14 Mark Mitchell + PR c++/26748 + * g++.dg/ext/attrib22.C: New test. + PR c++/26559 * g++.dg/template/builtin1.C: New test. * g++.dg/gomp/tpl-atomic-2.C: Remove XFAIL. diff --git a/gcc/testsuite/g++.dg/ext/attrib22.C b/gcc/testsuite/g++.dg/ext/attrib22.C new file mode 100644 index 00000000000..5304a35d177 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attrib22.C @@ -0,0 +1,6 @@ +// PR c++/27648 + +void f() +{ + static_cast(0); // { dg-error "expected" } +} -- 2.30.2