From 046608a3e0569946f4a499c59e02f45b057d7251 Mon Sep 17 00:00:00 2001 From: Nicola Pero Date: Sat, 8 Jan 2011 19:44:30 +0000 Subject: [PATCH] In gcc/: 2011-01-08 Nicola Pero In gcc/: 2011-01-08 Nicola Pero PR objc/47078 * c-parser.c (c_parser_objc_type_name): If the type is unknown, for error recovery purposes behave as if it was not specified so that the default type is usd. In gcc/testsuite/: 2011-01-08 Nicola Pero PR objc/47078 * objc.dg/invalid-method-2.m: New. * obj-c++.dg/invalid-method-2.mm: New. In gcc/cp/: 2011-01-08 Nicola Pero PR objc/47078 * parser.c (cp_parser_objc_typename): If the type is unknown, for error recovery purposes behave as if it was not specified so that the default type is used. From-SVN: r168601 --- gcc/ChangeLog | 7 +++++++ gcc/c-parser.c | 8 ++++++++ gcc/cp/ChangeLog | 7 +++++++ gcc/cp/parser.c | 20 +++++++++++++++++++- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/obj-c++.dg/invalid-method-2.mm | 18 ++++++++++++++++++ gcc/testsuite/objc.dg/invalid-method-2.m | 18 ++++++++++++++++++ 7 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/obj-c++.dg/invalid-method-2.mm create mode 100644 gcc/testsuite/objc.dg/invalid-method-2.m diff --git a/gcc/ChangeLog b/gcc/ChangeLog index aec3bbe4918..2efec7e7bdd 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2011-01-08 Nicola Pero + + PR objc/47078 + * c-parser.c (c_parser_objc_type_name): If the type is unknown, + for error recovery purposes behave as if it was not specified so + that the default type is usd. + 2011-01-07 Jan Hubicka PR tree-optmization/46469 diff --git a/gcc/c-parser.c b/gcc/c-parser.c index 1e868afddf6..cf34e041463 100644 --- a/gcc/c-parser.c +++ b/gcc/c-parser.c @@ -7482,6 +7482,14 @@ c_parser_objc_type_name (c_parser *parser) type_name = c_parser_type_name (parser); if (type_name) type = groktypename (type_name, NULL, NULL); + + /* If the type is unknown, and error has already been produced and + we need to recover from the error. In that case, use NULL_TREE + for the type, as if no type had been specified; this will use the + default type ('id') which is good for error recovery. */ + if (type == error_mark_node) + type = NULL_TREE; + return build_tree_list (quals, type); } diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 35d8864cd58..4cfe3e613b2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2011-01-08 Nicola Pero + + PR objc/47078 + * parser.c (cp_parser_objc_typename): If the type is unknown, for + error recovery purposes behave as if it was not specified so that + the default type is used. + 2011-01-07 Jakub Jelinek PR c++/47022 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 43e91b034cf..2f11f8ee908 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -21915,7 +21915,25 @@ cp_parser_objc_typename (cp_parser* parser) /* An ObjC type name may consist of just protocol qualifiers, in which case the type shall default to 'id'. */ if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN)) - cp_type = cp_parser_type_id (parser); + { + cp_type = cp_parser_type_id (parser); + + /* If the type could not be parsed, an error has already + been produced. For error recovery, behave as if it had + not been specified, which will use the default type + 'id'. */ + if (cp_type == error_mark_node) + { + cp_type = NULL_TREE; + /* We need to skip to the closing parenthesis as + cp_parser_type_id() does not seem to do it for + us. */ + cp_parser_skip_to_closing_parenthesis (parser, + /*recovering=*/true, + /*or_comma=*/false, + /*consume_paren=*/false); + } + } cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN); type_name = build_tree_list (proto_quals, cp_type); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2824845e5a6..459750ff4d0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2011-01-08 Nicola Pero + + PR objc/47078 + * objc.dg/invalid-method-2.m: New. + * obj-c++.dg/invalid-method-2.mm: New. + 2011-01-08 Paul Thomas PR fortran/46896 diff --git a/gcc/testsuite/obj-c++.dg/invalid-method-2.mm b/gcc/testsuite/obj-c++.dg/invalid-method-2.mm new file mode 100644 index 00000000000..48f03599c11 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/invalid-method-2.mm @@ -0,0 +1,18 @@ +/* { dg-do compile } */ + +/* Test that using an invalid type in a method declaration produces a + friendly error without a compiler crash. */ + +@interface MyClass +@end + +@implementation MyClass +- (x) method /* { dg-error "expected" } */ +{ + return 0; +} +- (id) method2: (x)argument /* { dg-error "expected" } */ +{ + return 0; +} +@end diff --git a/gcc/testsuite/objc.dg/invalid-method-2.m b/gcc/testsuite/objc.dg/invalid-method-2.m new file mode 100644 index 00000000000..cb18de95740 --- /dev/null +++ b/gcc/testsuite/objc.dg/invalid-method-2.m @@ -0,0 +1,18 @@ +/* { dg-do compile } */ + +/* Test that using an invalid type in a method declaration produces a + friendly error without a compiler crash. */ + +@interface MyClass +@end + +@implementation MyClass +- (x) method /* { dg-error "unknown type name" } */ +{ + return 0; +} +- (id) method2: (x)argument /* { dg-error "unknown type name" } */ +{ + return 0; +} +@end -- 2.11.4.GIT