PR c++/10603
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 17 Dec 2003 16:58:14 +0000 (16:58 +0000)
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 17 Dec 2003 16:58:14 +0000 (16:58 +0000)
PR c++/12827
* parser.c (cp_parser_error): Help c_parse_error print good
messages if the next token is a keyword.
(cp_parser_parameter_declaration_list): When resynchronizing after
a bad parameter declaration, stop if a comma is found.
(cp_parser_parameter_declaration): Avoid backtracking.

PR c++/10603
* g++.dg/parse/error6.C: New test.

PR c++/12827
* g++.dg/parse/error7.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@74743 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/error3.C
gcc/testsuite/g++.dg/parse/error6.C [new file with mode: 0644]
gcc/testsuite/g++.dg/parse/error7.C [new file with mode: 0644]

index fd63165..faa0fd6 100644 (file)
@@ -1,3 +1,13 @@
+2003-12-17  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/10603
+       PR c++/12827
+       * parser.c (cp_parser_error): Help c_parse_error print good
+       messages if the next token is a keyword.
+       (cp_parser_parameter_declaration_list): When resynchronizing after
+       a bad parameter declaration, stop if a comma is found.
+       (cp_parser_parameter_declaration): Avoid backtracking.
+
 2003-12-16  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/12696
index 8980611..789ccb0 100644 (file)
@@ -1771,7 +1771,12 @@ cp_parser_error (cp_parser* parser, const char* message)
     {
       cp_token *token;
       token = cp_lexer_peek_token (parser->lexer);
-      c_parse_error (message, token->type, token->value);
+      c_parse_error (message, 
+                    /* Because c_parser_error does not understand
+                       CPP_KEYWORD, keywords are treated like
+                       identifiers.  */
+                    (token->type == CPP_KEYWORD ? CPP_NAME : token->type), 
+                    token->value);
     }
 }
 
@@ -10804,7 +10809,7 @@ cp_parser_parameter_declaration_list (cp_parser* parser)
              || cp_parser_committed_to_tentative_parse (parser))
            cp_parser_skip_to_closing_parenthesis (parser, 
                                                   /*recovering=*/true,
-                                                  /*or_comma=*/true,
+                                                  /*or_comma=*/false,
                                                   /*consume_paren=*/false);
          break;
        }
@@ -10900,6 +10905,16 @@ cp_parser_parameter_declaration (cp_parser *parser,
       bool saved_default_arg_ok_p = parser->default_arg_ok_p;
       parser->default_arg_ok_p = false;
   
+      /* After seeing a decl-specifier-seq, if the next token is not a
+        "(", there is no possibility that the code is a valid
+        expression initializer.  Therefore, if parsing tentatively,
+        we commit at this point.  */
+      if (!parser->in_template_argument_list_p
+         && cp_parser_parsing_tentatively (parser)
+         && !cp_parser_committed_to_tentative_parse (parser)
+         && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_PAREN))
+       cp_parser_commit_to_tentative_parse (parser);
+      /* Parse the declarator.  */
       declarator = cp_parser_declarator (parser,
                                         CP_PARSER_DECLARATOR_EITHER,
                                         /*ctor_dtor_or_conv_p=*/NULL,
index 4830f69..91c4068 100644 (file)
@@ -1,3 +1,11 @@
+2003-12-17  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/10603
+       * g++.dg/parse/error6.C: New test.
+
+       PR c++/12827
+       * g++.dg/parse/error7.C: New test.
+
 2003-12-17  Eric Botcazou  <ebotcazou@libertysurf.fr>
 
        * lib/gcc-dg.exp (gcc-dg-debug-runtest): Do not run debug-[12].c
index 57b7896..a052346 100644 (file)
@@ -3,4 +3,4 @@
 static void InstantiateConstraint(const float&, unsigned,
                                   void(*AddFunction)(const TYPE&,bool&, // { dg-error "" }
                                                      char*, char*,
-                                                     unsigned*));
+                                                     unsigned*)); // { dg-error "" }
diff --git a/gcc/testsuite/g++.dg/parse/error6.C b/gcc/testsuite/g++.dg/parse/error6.C
new file mode 100644 (file)
index 0000000..3a16669
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/10603
+
+int f(int not) { // { dg-error "!" }
+  return 1-not; // { dg-error "" }
+} 
+
diff --git a/gcc/testsuite/g++.dg/parse/error7.C b/gcc/testsuite/g++.dg/parse/error7.C
new file mode 100644 (file)
index 0000000..50e7f84
--- /dev/null
@@ -0,0 +1,4 @@
+// PR c++/12827
+
+void f(int x
+       int y); // { dg-error "," }