diff options
author | Manuel López-Ibáñez <manu@gcc.gnu.org> | 2008-08-09 12:37:32 +0000 |
---|---|---|
committer | Manuel López-Ibáñez <manu@gcc.gnu.org> | 2008-08-09 12:37:32 +0000 |
commit | ca085fd7b7ba0cd12a6411cc0ff6a3380d82df0a (patch) | |
tree | c4488aadaa6e95ea5ce61510a777e178059a7519 /gcc/c-parser.c | |
parent | 98e48a7f11b14985b94ed8b86af0f97af1e7bda7 (diff) | |
download | gcc-ca085fd7b7ba0cd12a6411cc0ff6a3380d82df0a.zip gcc-ca085fd7b7ba0cd12a6411cc0ff6a3380d82df0a.tar.gz gcc-ca085fd7b7ba0cd12a6411cc0ff6a3380d82df0a.tar.bz2 |
re PR c++/17880 (-Wsequence-point doesn't warn inside if, while, do conditions, for beg/cond/end expressions etc.)
2008-08-09 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR c/17880
* c-typeck.c (digest_init): Call verify_sequence_points from here.
(c_finish_return): Likewise.
(c_start_case): Likewise.
* c-common.c (warn_for_collisions_1): Use explicit location in
warning.
* c-parser.c (c_parser_condition): New. Call
verify_sequence_points.
(c_parser_paren_condition): Call c_parser_condition.
(c_parser_for_statement): Call c_parser_condition.
testsuite/
* gcc.dg/sequence-pt-pr17880.c: New.
From-SVN: r138904
Diffstat (limited to 'gcc/c-parser.c')
-rw-r--r-- | gcc/c-parser.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/gcc/c-parser.c b/gcc/c-parser.c index a2ea45f..02fc785 100644 --- a/gcc/c-parser.c +++ b/gcc/c-parser.c @@ -3791,6 +3791,23 @@ c_parser_statement_after_labels (c_parser *parser) parser->in_if_block = in_if_block; } +/* Parse the condition from an if, do, while or for statements. */ + +static tree +c_parser_condition (c_parser *parser) +{ + location_t loc; + tree cond; + loc = c_parser_peek_token (parser)->location; + cond = c_objc_common_truthvalue_conversion + (c_parser_expression_conv (parser).value); + if (CAN_HAVE_LOCATION_P (cond)) + SET_EXPR_LOCATION (cond, loc); + if (warn_sequence_point) + verify_sequence_points (cond); + return cond; +} + /* Parse a parenthesized condition from an if, do or while statement. condition: @@ -3799,15 +3816,10 @@ c_parser_statement_after_labels (c_parser *parser) static tree c_parser_paren_condition (c_parser *parser) { - location_t loc; tree cond; if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) return error_mark_node; - loc = c_parser_peek_token (parser)->location; - cond = c_objc_common_truthvalue_conversion - (c_parser_expression_conv (parser).value); - if (CAN_HAVE_LOCATION_P (cond)) - SET_EXPR_LOCATION (cond, loc); + cond = c_parser_condition (parser); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); return cond; } @@ -4073,7 +4085,6 @@ c_parser_for_statement (c_parser *parser) c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); } /* Parse the loop condition. */ - loc = c_parser_peek_token (parser)->location; if (c_parser_next_token_is (parser, CPP_SEMICOLON)) { c_parser_consume_token (parser); @@ -4081,10 +4092,7 @@ c_parser_for_statement (c_parser *parser) } else { - tree ocond = c_parser_expression_conv (parser).value; - cond = c_objc_common_truthvalue_conversion (ocond); - if (CAN_HAVE_LOCATION_P (cond)) - SET_EXPR_LOCATION (cond, loc); + cond = c_parser_condition (parser); c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); } /* Parse the increment expression. */ |