re PR c++/9851 (confusing error message when using '.', not '->')
authorIan Lance Taylor <ian@wasabisystems.com>
Fri, 13 Feb 2004 16:11:39 +0000 (16:11 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Fri, 13 Feb 2004 16:11:39 +0000 (16:11 +0000)
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.

From-SVN: r77758

gcc/cp/ChangeLog
gcc/cp/parser.c

index 809dcfe876073c3fbd58ba19ec8b4780108e062d..4238dea0fc559343a0ba5374fdc6b5c0aa587108 100644 (file)
@@ -1,3 +1,10 @@
+2004-02-13  Ian Lance Taylor  <ian@wasabisystems.com>
+
+       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  <mark@codesourcery.com>
 
        * call.c (conversion_kind): New type.
index b17d669cd6dc2d86dfe9a773041d4acfa2ecf8a7..7918602dee3de06ae0e0299f107f3849f56d36df 100644 (file)
@@ -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, "`::'");
     }