From 60c6ea84ccef41e2fb963f7d47640108ff4167dd Mon Sep 17 00:00:00 2001 From: ian Date: Fri, 13 Feb 2004 16:11:39 +0000 Subject: [PATCH] PR c++/9851 * parser.c (cp_parser_pseudo_destructor_name): Check for errors on the type name and look ahead for ::~, and bail out early with a better error message if the parse is going to fail. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@77758 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/parser.c | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 809dcfe8760..4238dea0fc5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2004-02-13 Ian Lance Taylor + + PR c++/9851 + * parser.c (cp_parser_pseudo_destructor_name): Check for errors on + the type name and look ahead for ::~, and bail out early with a + better error message if the parse is going to fail. + 2004-02-12 Mark Mitchell * call.c (conversion_kind): New type. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index b17d669cd6d..7918602dee3 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -4187,7 +4187,7 @@ cp_parser_parenthesized_expression_list (cp_parser* parser, If either of the first two productions is used, sets *SCOPE to the TYPE specified before the final `::'. Otherwise, *SCOPE is set to NULL_TREE. *TYPE is set to the TYPE_DECL for the final type-name, - or ERROR_MARK_NODE if no type-name is present. */ + or ERROR_MARK_NODE if the parse fails. */ static void cp_parser_pseudo_destructor_name (cp_parser* parser, @@ -4227,6 +4227,21 @@ cp_parser_pseudo_destructor_name (cp_parser* parser, { /* Look for the type-name. */ *scope = TREE_TYPE (cp_parser_type_name (parser)); + + /* If we didn't get an aggregate type, or we don't have ::~, + then something has gone wrong. Since the only caller of this + function is looking for something after `.' or `->' after a + scalar type, most likely the program is trying to get a + member of a non-aggregate type. */ + if (*scope == error_mark_node + || cp_lexer_next_token_is_not (parser->lexer, CPP_SCOPE) + || cp_lexer_peek_nth_token (parser->lexer, 2)->type != CPP_COMPL) + { + cp_parser_error (parser, "request for member of non-aggregate type"); + *type = error_mark_node; + return; + } + /* Look for the `::' token. */ cp_parser_require (parser, CPP_SCOPE, "`::'"); } -- 2.11.4.GIT