This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 16215
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 17 Aug 2004 17:59:39 -0700
- Subject: C++ PATCH: PR 16215
- Reply-to: mark at codesourcery dot com
This patch fixes an error-message regression in the new parser.
Tested on i686-pc-linux-gnu, applied on the mainline. This is a 3.4.x
regression too, but it is not worth the risk to apply it there.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
2004-08-17 Mark Mitchell <mark@codesourcery.com>
PR c++/16215
* parser.c (cp_parser_name_lookup_error): If parser->object_scope
is set use it for diagnostic purposes.
(cp_parser_pseudo_destructor_name): Remove special-case error
message.
Index: parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.237
diff -c -5 -p -r1.237 parser.c
*** parser.c 17 Aug 2004 17:32:33 -0000 1.237
--- parser.c 18 Aug 2004 00:55:19 -0000
*************** cp_parser_name_lookup_error (cp_parser*
*** 2016,2025 ****
--- 2016,2032 ----
if (parser->scope && parser->scope != global_namespace)
error ("`%D::%D' has not been declared",
parser->scope, name);
else if (parser->scope == global_namespace)
error ("`::%D' has not been declared", name);
+ else if (parser->object_scope
+ && !CLASS_TYPE_P (parser->object_scope))
+ error ("request for member `%D' in non-class type `%T'",
+ name, parser->object_scope);
+ else if (parser->object_scope)
+ error ("`%T::%D' has not been declared",
+ parser->object_scope, name);
else
error ("`%D' has not been declared", name);
}
else if (parser->scope && parser->scope != global_namespace)
error ("`%D::%D' %s", parser->scope, name, desired);
*************** cp_parser_pseudo_destructor_name (cp_par
*** 4486,4495 ****
--- 4493,4505 ----
tree* scope,
tree* type)
{
bool nested_name_specifier_p;
+ /* Assume that things will not work out. */
+ *type = error_mark_node;
+
/* Look for the optional `::' operator. */
cp_parser_global_scope_opt (parser, /*current_scope_valid_p=*/true);
/* Look for the optional nested-name-specifier. */
nested_name_specifier_p
= (cp_parser_nested_name_specifier_opt (parser,
*************** cp_parser_pseudo_destructor_name (cp_par
*** 4518,4538 ****
else if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMPL))
{
/* 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, "`::'");
--- 4528,4549 ----
else if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMPL))
{
/* Look for the type-name. */
*scope = TREE_TYPE (cp_parser_type_name (parser));
! if (*scope == error_mark_node)
! return;
!
! /* If 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 (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");
return;
}
/* Look for the `::' token. */
cp_parser_require (parser, CPP_SCOPE, "`::'");