diff options
author | Dodji Seketeli <dodji@redhat.com> | 2012-10-10 10:24:35 +0000 |
---|---|---|
committer | Dodji Seketeli <dodji@gcc.gnu.org> | 2012-10-10 12:24:35 +0200 |
commit | d32350e7a5eb5d31aaa1643dbc9db569fbc59b49 (patch) | |
tree | 808a7094d3bc267b2c5af74bca6f47c4072d6400 | |
parent | 137456439a3e92879acdda2a7e8fdff7c0c23142 (diff) | |
download | gcc-d32350e7a5eb5d31aaa1643dbc9db569fbc59b49.zip gcc-d32350e7a5eb5d31aaa1643dbc9db569fbc59b49.tar.gz gcc-d32350e7a5eb5d31aaa1643dbc9db569fbc59b49.tar.bz2 |
Disambiguate nested objc-message-expressions and c++11 attributes
A couple of obj-c++ tests were failing[1] because the tokens '[[' can
either be the beginning of a c++11 attribute (that is itself at the
beginning of a statement), or the beginning of a nested
objc-message-expression. This patch resolves the ambiguity by
tentatively parsing the c++11 attribute and if it fails, then consider
the objc-message-expression.
I missed this initially because it didn't occur to me that
--enable-languages=all,ada does not include obj-c++. Shame on me. I
have now updated my compile farm scripts to use
--enable-language=all,ada,obj-c++,go and I
[1]:
FAIL: obj-c++.dg/syntax-error-6.mm -fgnu-runtime (test for errors, line 11)
FAIL: obj-c++.dg/syntax-error-6.mm -fgnu-runtime (test for excess errors)
FAIL: obj-c++.dg/template-8.mm -fgnu-runtime (test for excess errors)
Tested on x86_64-unknown-linux-gnu against trunk.
gcc/cp/
* parser (cp_parser_statement): Parse c++11 attributes tentatively.
(cp_parser_std_attribute_spec_seq): Do not warn too early about
using c++11 attributes in non c++11 mode.
From-SVN: r192299
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/parser.c | 15 |
2 files changed, 21 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 68ebb96..208d305 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2012-10-10 Dodji Seketeli <dodji@redhat.com> + + * parser (cp_parser_statement): Parse c++11 attributes + tentatively. + (cp_parser_std_attribute_spec_seq): Do not warn too early about + using c++11 attributes in non c++11 mode. + 2012-10-10 Dehao Chen <dehao@google.com> * cp-gimplify.c (cp_genericize_r): Set location for TRY expr. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index e2b355a..a7939c8 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -8718,7 +8718,17 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr, cp_lexer_save_tokens (parser->lexer); attrs_location = cp_lexer_peek_token (parser->lexer)->location; + if (c_dialect_objc ()) + /* In obj-c++, seing '[[' might be the either the beginning of + c++11 attributes, or a nested objc-message-expression. So + let's parse the c++11 attributes tentatively. */ + cp_parser_parse_tentatively (parser); std_attrs = cp_parser_std_attribute_spec_seq (parser); + if (c_dialect_objc ()) + { + if (!cp_parser_parse_definitely (parser)) + std_attrs = NULL_TREE; + } /* Peek at the next token. */ token = cp_lexer_peek_token (parser->lexer); @@ -20703,7 +20713,6 @@ cp_parser_std_attribute_spec (cp_parser *parser) && cp_lexer_peek_nth_token (parser->lexer, 2)->type == CPP_OPEN_SQUARE) { cp_lexer_consume_token (parser->lexer); - maybe_warn_cpp0x (CPP0X_ATTRIBUTES); cp_lexer_consume_token (parser->lexer); attributes = cp_parser_std_attribute_list (parser); @@ -20711,6 +20720,10 @@ cp_parser_std_attribute_spec (cp_parser *parser) if (!cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE) || !cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE)) cp_parser_skip_to_end_of_statement (parser); + else + /* Warn about parsing c++11 attribute in non-c++1 mode, only + when we are sure that we have actually parsed them. */ + maybe_warn_cpp0x (CPP0X_ATTRIBUTES); } else { |