This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 16002 and 16029
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 17 Sep 2004 00:10:10 -0700
- Subject: C++ PATCH: PR 16002 and 16029
- Reply-to: mark at codesourcery dot com
These two PRs both relate to bad error messages. PR 16002 is:
void f() { double Q *= 5.0; }
We used to say:
te.cpp:3: error: expected primary-expression before "double"
te.cpp:3: error: expected `;' before "double"
Now, we commit to the tentative parse after seeing "double", and
thereby say:
te.cpp:3: error: expected initializer before '*=' token
PR 16029 was a case where we complained about variables that we
conjured up for error recovery being unused, which is clearly
pointless.
Tested on i686-pc-linux-gnu, applied on the mainline. I'll be
applying the fix for 16002 to the 3.4 branch after testing completes
there.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
2004-09-16 Mark Mitchell <mark@codesourcery.com>
PR c++/16002
* parser.c (cp_parser_simple_declaration): Commit to tentative
parses after seeing a decl-specifier.
(cp_parser_simple_declaration): Eliminate spurious message.
(cp_parser_init_declarator): Adjust error message.
PR c++/16029
* lex.c (unqualified_name_lookup_error): Mark the dummy
declaration as used.
2004-09-16 Mark Mitchell <mark@codesourcery.com>
PR c++/16002
* g++.dg/template/error18.C: New test.
PR c++/16029
* g++.dg/warn/Wunused-8.C: New test.
Index: cp/lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/lex.c,v
retrieving revision 1.344
diff -c -5 -p -r1.344 lex.c
*** cp/lex.c 10 Sep 2004 23:56:31 -0000 1.344
--- cp/lex.c 17 Sep 2004 06:58:06 -0000
*************** unqualified_name_lookup_error (tree name
*** 570,579 ****
--- 570,582 ----
{
tree decl;
decl = build_decl (VAR_DECL, name, error_mark_node);
DECL_CONTEXT (decl) = current_function_decl;
push_local_binding (name, decl, 0);
+ /* Mark the variable as used so that we do not get warnings
+ about it being unused later. */
+ TREE_USED (decl) = 1;
}
}
return error_mark_node;
}
Index: cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.248
diff -c -5 -p -r1.248 parser.c
*** cp/parser.c 16 Sep 2004 22:55:09 -0000 1.248
--- cp/parser.c 17 Sep 2004 06:58:06 -0000
*************** cp_parser_simple_declaration (cp_parser*
*** 7024,7033 ****
--- 7024,7040 ----
looking at a declaration. */
cp_parser_commit_to_tentative_parse (parser);
/* Give up. */
goto done;
}
+
+ /* If we have seen at least one decl-specifier, and the next token
+ is not a parenthesis, then we must be looking at a declaration.
+ (After "int (" we might be looking at a functional cast.) */
+ if (decl_specifiers.any_specifiers_p
+ && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_PAREN))
+ cp_parser_commit_to_tentative_parse (parser);
/* Keep going until we hit the `;' at the end of the simple
declaration. */
saw_declarator = false;
while (cp_lexer_next_token_is_not (parser->lexer,
*************** cp_parser_simple_declaration (cp_parser*
*** 7077,7087 ****
else if (token->type == CPP_SEMICOLON)
break;
/* Anything else is an error. */
else
{
! cp_parser_error (parser, "expected `,' or `;'");
/* Skip tokens until we reach the end of the statement. */
cp_parser_skip_to_end_of_statement (parser);
/* If the next token is now a `;', consume it. */
if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
cp_lexer_consume_token (parser->lexer);
--- 7084,7099 ----
else if (token->type == CPP_SEMICOLON)
break;
/* Anything else is an error. */
else
{
! /* If we have already issued an error message we don't need
! to issue another one. */
! if (decl != error_mark_node
! || (cp_parser_parsing_tentatively (parser)
! && !cp_parser_committed_to_tentative_parse (parser)))
! cp_parser_error (parser, "expected `,' or `;'");
/* Skip tokens until we reach the end of the statement. */
cp_parser_skip_to_end_of_statement (parser);
/* If the next token is now a `;', consume it. */
if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
cp_lexer_consume_token (parser->lexer);
*************** cp_parser_init_declarator (cp_parser* pa
*** 10639,10649 ****
`,' or `;', it's not a valid init-declarator. */
if (!is_initialized
&& token->type != CPP_COMMA
&& token->type != CPP_SEMICOLON)
{
! cp_parser_error (parser, "expected init-declarator");
return error_mark_node;
}
/* Because start_decl has side-effects, we should only call it if we
know we're going ahead. By this point, we know that we cannot
--- 10651,10661 ----
`,' or `;', it's not a valid init-declarator. */
if (!is_initialized
&& token->type != CPP_COMMA
&& token->type != CPP_SEMICOLON)
{
! cp_parser_error (parser, "expected initializer");
return error_mark_node;
}
/* Because start_decl has side-effects, we should only call it if we
know we're going ahead. By this point, we know that we cannot
Index: testsuite/g++.dg/parse/error18.C
===================================================================
RCS file: testsuite/g++.dg/parse/error18.C
diff -N testsuite/g++.dg/parse/error18.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/parse/error18.C 17 Sep 2004 06:58:06 -0000
***************
*** 0 ****
--- 1,7 ----
+ // PR c++/16002
+
+ void f()
+ {
+ double Q *= 5.0; // { dg-error "initializer" }
+ }
+
Index: testsuite/g++.dg/warn/Wunused-8.C
===================================================================
RCS file: testsuite/g++.dg/warn/Wunused-8.C
diff -N testsuite/g++.dg/warn/Wunused-8.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/warn/Wunused-8.C 17 Sep 2004 06:58:06 -0000
***************
*** 0 ****
--- 1,9 ----
+ // PR c++/16029
+ // { dg-options "-Wunused" }
+
+ int main ()
+ {
+ // We should not see an "unused" warning about "whatever" on the
+ // next line.
+ return whatever (); // { dg-error "declared" }
+ }