aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2014-06-27 07:46:04 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2014-06-27 07:46:04 +0000
commitfcbbf14a65cb7cb5814087870a0ecb47c227592c (patch)
tree802b3594f135651fb3a071931354cede040f2a5a
parenta4ee446d6d7f1c120e9ef281ec4586f7535647cc (diff)
downloadgcc-fcbbf14a65cb7cb5814087870a0ecb47c227592c.zip
gcc-fcbbf14a65cb7cb5814087870a0ecb47c227592c.tar.gz
gcc-fcbbf14a65cb7cb5814087870a0ecb47c227592c.tar.bz2
parser.c (cp_parser_compound_literal_p): New.
2014-06-27 Paolo Carlini <paolo.carlini@oracle.com> * parser.c (cp_parser_compound_literal_p): New. (cp_parser_postfix_expression, cp_parser_sizeof_operand): Use it. From-SVN: r212064
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/parser.c61
2 files changed, 34 insertions, 32 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 6fbd27a..e8aee0f 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2014-06-27 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * parser.c (cp_parser_compound_literal_p): New.
+ (cp_parser_postfix_expression, cp_parser_sizeof_operand): Use it.
+
2014-06-26 Jason Merrill <jason@redhat.com>
* parser.c (cp_parser_for_init_statement): Change range-for error
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index a7edd41..057b6ca 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -2480,7 +2480,9 @@ static bool cp_parser_is_keyword
static tree cp_parser_make_typename_type
(cp_parser *, tree, tree, location_t location);
static cp_declarator * cp_parser_make_indirect_declarator
- (enum tree_code, tree, cp_cv_quals, cp_declarator *, tree);
+ (enum tree_code, tree, cp_cv_quals, cp_declarator *, tree);
+static bool cp_parser_compound_literal_p
+ (cp_parser *);
/* Returns nonzero if we are parsing tentatively. */
@@ -5609,6 +5611,30 @@ cp_parser_qualifying_entity (cp_parser *parser,
return scope;
}
+/* Return true if we are looking at a compound-literal, false otherwise. */
+
+static bool
+cp_parser_compound_literal_p (cp_parser *parser)
+{
+ /* Consume the `('. */
+ cp_lexer_consume_token (parser->lexer);
+
+ cp_lexer_save_tokens (parser->lexer);
+
+ /* Skip tokens until the next token is a closing parenthesis.
+ If we find the closing `)', and the next token is a `{', then
+ we are looking at a compound-literal. */
+ bool compound_literal_p
+ = (cp_parser_skip_to_closing_parenthesis (parser, false, false,
+ /*consume_paren=*/true)
+ && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE));
+
+ /* Roll back the tokens we skipped. */
+ cp_lexer_rollback_tokens (parser->lexer);
+
+ return compound_literal_p;
+}
+
/* Parse a postfix-expression.
postfix-expression:
@@ -5917,25 +5943,12 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
&& cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
{
tree initializer = NULL_TREE;
- bool compound_literal_p;
cp_parser_parse_tentatively (parser);
- /* Consume the `('. */
- cp_lexer_consume_token (parser->lexer);
/* Avoid calling cp_parser_type_id pointlessly, see comment
in cp_parser_cast_expression about c++/29234. */
- cp_lexer_save_tokens (parser->lexer);
-
- compound_literal_p
- = (cp_parser_skip_to_closing_parenthesis (parser, false, false,
- /*consume_paren=*/true)
- && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE));
-
- /* Roll back the tokens we skipped. */
- cp_lexer_rollback_tokens (parser->lexer);
-
- if (!compound_literal_p)
+ if (!cp_parser_compound_literal_p (parser))
cp_parser_simulate_error (parser);
else
{
@@ -23966,31 +23979,15 @@ cp_parser_sizeof_operand (cp_parser* parser, enum rid keyword)
if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
{
tree type = NULL_TREE;
- bool compound_literal_p;
/* We can't be sure yet whether we're looking at a type-id or an
expression. */
cp_parser_parse_tentatively (parser);
- /* Consume the `('. */
- cp_lexer_consume_token (parser->lexer);
/* Note: as a GNU Extension, compound literals are considered
postfix-expressions as they are in C99, so they are valid
arguments to sizeof. See comment in cp_parser_cast_expression
for details. */
- cp_lexer_save_tokens (parser->lexer);
- /* Skip tokens until the next token is a closing parenthesis.
- If we find the closing `)', and the next token is a `{', then
- we are looking at a compound-literal. */
- compound_literal_p
- = (cp_parser_skip_to_closing_parenthesis (parser, false, false,
- /*consume_paren=*/true)
- && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE));
- /* Roll back the tokens we skipped. */
- cp_lexer_rollback_tokens (parser->lexer);
- /* If we were looking at a compound-literal, simulate an error
- so that the call to cp_parser_parse_definitely below will
- fail. */
- if (compound_literal_p)
+ if (cp_parser_compound_literal_p (parser))
cp_parser_simulate_error (parser);
else
{