diff options
author | Mark Mitchell <mark@codesourcery.com> | 2003-12-17 16:58:14 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 2003-12-17 16:58:14 +0000 |
commit | 5c832178f89fcb4115dab67587c694f654c23d1d (patch) | |
tree | ab32363f39e685469055a01af67df1879b9c1fc8 /gcc | |
parent | 8f0f6aa1fd95249ff405378b1716dc9050e72401 (diff) | |
download | gcc-5c832178f89fcb4115dab67587c694f654c23d1d.zip gcc-5c832178f89fcb4115dab67587c694f654c23d1d.tar.gz gcc-5c832178f89fcb4115dab67587c694f654c23d1d.tar.bz2 |
re PR c++/10603 (failing to print problematic token upon parse error)
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.
PR c++/10603
* g++.dg/parse/error6.C: New test.
PR c++/12827
* g++.dg/parse/error7.C: New test.
From-SVN: r74743
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/cp/parser.c | 19 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/parse/error3.C | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/parse/error6.C | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/parse/error7.C | 4 |
6 files changed, 46 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index fd63165..faa0fd6 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -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 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 8980611..789ccb0 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -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, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4830f69..91c4068 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 diff --git a/gcc/testsuite/g++.dg/parse/error3.C b/gcc/testsuite/g++.dg/parse/error3.C index 57b7896..a052346 100644 --- a/gcc/testsuite/g++.dg/parse/error3.C +++ b/gcc/testsuite/g++.dg/parse/error3.C @@ -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 index 0000000..3a16669 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/error6.C @@ -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 index 0000000..50e7f84 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/error7.C @@ -0,0 +1,4 @@ +// PR c++/12827 + +void f(int x + int y); // { dg-error "," } |