OSDN Git Service

cp/:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 25 Jun 2009 19:03:28 +0000 (19:03 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 25 Jun 2009 19:03:28 +0000 (19:03 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@148949 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/skip-2.C [new file with mode: 0644]

index fc9de2d..4e1f610 100644 (file)
@@ -1,3 +1,11 @@
+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.
 2009-06-24  Jason Merrill  <jason@redhat.com>
 
        * error.c (dump_decl): Do say "typedef" for the injected class name.
index bdf3058..f71ea46 100644 (file)
@@ -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);
 
       /* 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);
       /* 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;
        }
 
          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.
       overloaded_p = false;
       /* ??? Currently we pass lhs_type == ERROR_MARK and rhs_type ==
         ERROR_MARK for everything that is not a binary expression.
index e3ed871..0799db3 100644 (file)
@@ -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
          /* 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);
        {
          warn_for_sign_compare (location, orig_op0, orig_op1, op0, op1, 
                                 result_type, resultcode);
index 88ea4f5..cf0a4d9 100644 (file)
@@ -1,3 +1,7 @@
+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
 2009-06-25  Steve Ellcey  <sje@cup.hp.com>
 
        * gcc.c-torture/execute/20090618-1.c: add dg-run and
diff --git a/gcc/testsuite/g++.dg/warn/skip-2.C b/gcc/testsuite/g++.dg/warn/skip-2.C
new file mode 100644 (file)
index 0000000..28f9049
--- /dev/null
@@ -0,0 +1,37 @@
+// { 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();
+}