Commit 98f80e91 by Ian Lance Taylor Committed by Ian Lance Taylor

parser.c (cp_parser_binary_expression): Increment c_inhibit_evaluation_warnings…

parser.c (cp_parser_binary_expression): Increment c_inhibit_evaluation_warnings while parsing the right hand side of...

cp/:
	* parser.c (cp_parser_binary_expression): Increment
	c_inhibit_evaluation_warnings while parsing the right hand side of
	"true || x" or "false && x".
	* typeck.c (cp_build_binary_op): Only call warn_for_sign_compare
	if c_inhibit_evaluation_warnings is zero.
testsuite/:
	* g++.dg/warn/skip-2.C: New testcase.

From-SVN: r148949
parent 777a3a6a
2009-06-25 Ian Lance Taylor <iant@google.com>
* parser.c (cp_parser_binary_expression): Increment
c_inhibit_evaluation_warnings while parsing the right hand side of
"true || x" or "false && x".
* typeck.c (cp_build_binary_op): Only call warn_for_sign_compare
if c_inhibit_evaluation_warnings is zero.
2009-06-24 Jason Merrill <jason@redhat.com>
* error.c (dump_decl): Do say "typedef" for the injected class name.
......
......@@ -6287,6 +6287,13 @@ cp_parser_binary_expression (cp_parser* parser, bool cast_p,
/* We used the operator token. */
cp_lexer_consume_token (parser->lexer);
/* For "false && x" or "true || x", x will never be executed;
disable warnings while evaluating it. */
if (tree_type == TRUTH_ANDIF_EXPR)
c_inhibit_evaluation_warnings += lhs == truthvalue_false_node;
else if (tree_type == TRUTH_ORIF_EXPR)
c_inhibit_evaluation_warnings += lhs == truthvalue_true_node;
/* Extract another operand. It may be the RHS of this expression
or the LHS of a new, higher priority expression. */
rhs = cp_parser_simple_cast_expression (parser);
......@@ -6332,6 +6339,12 @@ cp_parser_binary_expression (cp_parser* parser, bool cast_p,
lhs_type = sp->lhs_type;
}
/* Undo the disabling of warnings done above. */
if (tree_type == TRUTH_ANDIF_EXPR)
c_inhibit_evaluation_warnings -= lhs == truthvalue_false_node;
else if (tree_type == TRUTH_ORIF_EXPR)
c_inhibit_evaluation_warnings -= lhs == truthvalue_true_node;
overloaded_p = false;
/* ??? Currently we pass lhs_type == ERROR_MARK and rhs_type ==
ERROR_MARK for everything that is not a binary expression.
......
......@@ -4021,7 +4021,8 @@ cp_build_binary_op (location_t location,
/* Do not warn until the template is instantiated; we cannot
bound the ranges of the arguments until that point. */
&& !processing_template_decl
&& (complain & tf_warning))
&& (complain & tf_warning)
&& c_inhibit_evaluation_warnings == 0)
{
warn_for_sign_compare (location, orig_op0, orig_op1, op0, op1,
result_type, resultcode);
......
2009-06-25 Ian Lance Taylor <iant@google.com>
* g++.dg/warn/skip-2.C: New testcase.
2009-06-25 Steve Ellcey <sje@cup.hp.com>
* gcc.c-torture/execute/20090618-1.c: add dg-run and
......
// { dg-do compile }
// { dg-options "-Wall" }
extern int f2(int);
extern void f3();
void
f1(int i)
{
if (1 == 1 || f2(i >> -10))
f3();
if (1 == 1 || f2(i >> 128))
f3();
if (1 == 1 || f2(i << -10))
f3();
if (1 == 1 || f2(i << 128))
f3();
if (1 == 1 || i < 0xffffffff)
f3();
if (1 == 1 || i >= -0x80000000)
f3();
if (1 == 0 && f2(i >> -10))
f3();
if (1 == 0 && f2(i >> 128))
f3();
if (1 == 0 && f2(i << -10))
f3();
if (1 == 0 && f2(i << 128))
f3();
if (1 == 0 && i < 0xffffffff)
f3();
if (1 == 0 && i >= -0x80000000)
f3();
if (1 == 1 && f2(i >> -10)) /* { dg-warning "shift count is negative" } */
f3();
if (1 == 0 || f2(i << -10)) /* { dg-warning "shift count is negative" } */
f3();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment