Let's beef up warn_for_sign_compare checks; we'd folded the operands
and they could've become garbage.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2018-03-02  Marek Polacek  <pola...@redhat.com>

        PR c++/84171
        * c-warn.c (warn_for_sign_compare): Bail out if any of the operands
        is erroneous.

        * g++.dg/warn/Wsign-compare-8.C: New test.

diff --git gcc/c-family/c-warn.c gcc/c-family/c-warn.c
index f3fb62c7e62..7c385959c4f 100644
--- gcc/c-family/c-warn.c
+++ gcc/c-family/c-warn.c
@@ -1931,6 +1931,9 @@ warn_for_sign_compare (location_t location,
                       tree op0, tree op1,
                       tree result_type, enum tree_code resultcode)
 {
+  if (error_operand_p (orig_op0) || error_operand_p (orig_op1))
+    return;
+
   int op0_signed = !TYPE_UNSIGNED (TREE_TYPE (orig_op0));
   int op1_signed = !TYPE_UNSIGNED (TREE_TYPE (orig_op1));
   int unsignedp0, unsignedp1;
diff --git gcc/testsuite/g++.dg/warn/Wsign-compare-8.C 
gcc/testsuite/g++.dg/warn/Wsign-compare-8.C
index e69de29bb2d..237ba84d526 100644
--- gcc/testsuite/g++.dg/warn/Wsign-compare-8.C
+++ gcc/testsuite/g++.dg/warn/Wsign-compare-8.C
@@ -0,0 +1,8 @@
+// PR c++/84171
+// { dg-options "-Wsign-compare" }
+
+bool foo (char c)
+{
+  const int i = 0 = 0; // { dg-error "lvalue" }
+  return c = i;
+} // { dg-warning "control reaches" }

        Marek

Reply via email to