This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: Fix PR 9112
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 31 Dec 2002 10:41:17 -0800
- Subject: C++ PATCH: Fix PR 9112
- Reply-to: mark at codesourcery dot com
This patch fixes a bug in the new parser whereby we tried to hard to
make declarations out of things that were not.
Tested on i686-pc-linux-gnu, applied on the mainline.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
2002-12-31 Mark Mitchell <mark@codesourcery.com>
PR c++/9112
* parser.c (cp_parser_direct_declarator): Handle erroneous
parenthesized declarators correctly.
2002-12-31 Mark Mitchell <mark@codesourcery.com>
PR c++/9112
* g++.dg/parse/expr1.C: New test.
Index: testsuite/g++.dg/parse/expr1.C
===================================================================
RCS file: testsuite/g++.dg/parse/expr1.C
diff -N testsuite/g++.dg/parse/expr1.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/parse/expr1.C 31 Dec 2002 18:38:06 -0000
***************
*** 0 ****
--- 1,8 ----
+ struct A {
+ A (int, int);
+ void f ();
+ };
+
+ void f (int a) {
+ A (a, a).f ();
+ }
Index: cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.7
diff -c -p -r1.7 parser.c
*** cp/parser.c 31 Dec 2002 00:11:47 -0000 1.7
--- cp/parser.c 31 Dec 2002 18:38:10 -0000
*************** cp_parser_direct_declarator (parser, abs
*** 10023,10028 ****
--- 10023,10030 ----
declarator. */
if (token->type == CPP_OPEN_PAREN)
{
+ bool error_p;
+
/* For an abstract declarator we do not know whether we are
looking at the beginning of a parameter-declaration-clause,
or at a parenthesized abstract declarator. For example, if
*************** cp_parser_direct_declarator (parser, abs
*** 10041,10047 ****
declarator
= cp_parser_declarator (parser, abstract_p, ctor_dtor_or_conv_p);
/* Expect a `)'. */
! cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
/* If parsing a parenthesized abstract declarator didn't work,
try a parameter-declaration-clause. */
--- 10043,10049 ----
declarator
= cp_parser_declarator (parser, abstract_p, ctor_dtor_or_conv_p);
/* Expect a `)'. */
! error_p = !cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
/* If parsing a parenthesized abstract declarator didn't work,
try a parameter-declaration-clause. */
*************** cp_parser_direct_declarator (parser, abs
*** 10050,10056 ****
/* If we were not parsing an abstract declarator, but failed to
find a satisfactory nested declarator, then an error has
occurred. */
! else if (!abstract_p && declarator == error_mark_node)
return error_mark_node;
/* Default args cannot appear in an abstract decl. */
parser->default_arg_ok_p = false;
--- 10052,10059 ----
/* If we were not parsing an abstract declarator, but failed to
find a satisfactory nested declarator, then an error has
occurred. */
! else if (!abstract_p
! && (declarator == error_mark_node || error_p))
return error_mark_node;
/* Default args cannot appear in an abstract decl. */
parser->default_arg_ok_p = false;