This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 13950 and PR 13970
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 3 Feb 2004 12:05:55 -0800
- Subject: C++ PATCH: PR 13950 and PR 13970
- Reply-to: mark at codesourcery dot com
This patch fixes two error handling regressions in the new parser.
Tested on i686-pc-linux-gnu, applied on the mainline and on the 3.4
branch.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
2004-02-03 Mark Mitchell <mark@codesourcery.com>
PR c++/13950
* parser.c (cp_parser_class_name): Robustify.
PR c++/13970
* parser.c (cp_parser_cache_group): Do not consume the EOF token.
2004-02-03 Mark Mitchell <mark@codesourcery.com>
PR c++/13950
* g++.dg/template/lookup4.C: New test.
PR c++/13970
* g++.dg/parse/error14.C: New test.
Index: cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.166
diff -c -5 -p -r1.166 parser.c
*** cp/parser.c 3 Feb 2004 16:53:24 -0000 1.166
--- cp/parser.c 3 Feb 2004 19:59:15 -0000
*************** cp_parser_class_name (cp_parser *parser,
*** 11620,11631 ****
decl = cp_parser_maybe_treat_template_as_class (decl, class_head_p);
/* If this is a typename, create a TYPENAME_TYPE. */
if (typename_p && decl != error_mark_node)
! decl = TYPE_NAME (make_typename_type (scope, decl,
! /*complain=*/1));
/* Check to see that it is really the name of a class. */
if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
&& TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
&& cp_lexer_next_token_is (parser->lexer, CPP_SCOPE))
--- 11620,11634 ----
decl = cp_parser_maybe_treat_template_as_class (decl, class_head_p);
/* If this is a typename, create a TYPENAME_TYPE. */
if (typename_p && decl != error_mark_node)
! {
! decl = make_typename_type (scope, decl, /*complain=*/1);
! if (decl != error_mark_node)
! decl = TYPE_NAME (decl);
! }
/* Check to see that it is really the name of a class. */
if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
&& TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
&& cp_lexer_next_token_is (parser->lexer, CPP_SCOPE))
*************** cp_parser_cache_group (cp_parser *parser
*** 15067,15081 ****
/* Abort a parenthesized expression if we encounter a brace. */
if ((end == CPP_CLOSE_PAREN || depth == 0)
&& cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
return;
- /* Consume the next token. */
- token = cp_lexer_consume_token (parser->lexer);
/* If we've reached the end of the file, stop. */
! if (token->type == CPP_EOF)
return;
/* Add this token to the tokens we are saving. */
cp_token_cache_push_token (cache, token);
/* See if it starts a new group. */
if (token->type == CPP_OPEN_BRACE)
{
--- 15070,15084 ----
/* Abort a parenthesized expression if we encounter a brace. */
if ((end == CPP_CLOSE_PAREN || depth == 0)
&& cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
return;
/* If we've reached the end of the file, stop. */
! if (cp_lexer_next_token_is (parser->lexer, CPP_EOF))
return;
+ /* Consume the next token. */
+ token = cp_lexer_consume_token (parser->lexer);
/* Add this token to the tokens we are saving. */
cp_token_cache_push_token (cache, token);
/* See if it starts a new group. */
if (token->type == CPP_OPEN_BRACE)
{
Index: testsuite/g++.dg/parse/error14.C
===================================================================
RCS file: testsuite/g++.dg/parse/error14.C
diff -N testsuite/g++.dg/parse/error14.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/parse/error14.C 3 Feb 2004 19:59:16 -0000
***************
*** 0 ****
--- 1,22 ----
+ // PR c++/13970
+
+ struct X
+ {
+ template< typename Z > Z Zunc()
+ {
+ return Z();
+ }
+
+ template< typename Z > void Zinc()
+ {
+ }
+
+ void tst()
+ {
+ Zunc<int>();
+
+ Zinc<int>( //);
+ // }
+
+ }; // { dg-error "" }
+
Index: testsuite/g++.dg/template/lookup4.C
===================================================================
RCS file: testsuite/g++.dg/template/lookup4.C
diff -N testsuite/g++.dg/template/lookup4.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/lookup4.C 3 Feb 2004 19:59:16 -0000
***************
*** 0 ****
--- 1,6 ----
+ // PR c++/13950
+
+ template <class T> struct Base {};
+ template <class T> struct Derived: public Base<T> {
+ typename Derived::template Base<double>* p1; // { dg-error "" }
+ };