re PR c++/84171 (ICE with -Wsign-compare)
authorMarek Polacek <polacek@redhat.com>
Fri, 2 Mar 2018 17:51:24 +0000 (17:51 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 2 Mar 2018 17:51:24 +0000 (17:51 +0000)
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.

From-SVN: r258147

gcc/c-family/ChangeLog
gcc/c-family/c-warn.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wsign-compare-8.C [new file with mode: 0644]

index 27cc43e..fe1fc81 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-02  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/84171
+       * c-warn.c (warn_for_sign_compare): Bail out if any of the operands
+       is erroneous.
+
 2018-03-02  Thomas Schwinge  <thomas@codesourcery.com>
 
        * c-attribs.c (c_common_attribute_table): Remove "cilk simd
index f3fb62c..7c38595 100644 (file)
@@ -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;
index 0c73e80..a848cd3 100644 (file)
@@ -1,3 +1,8 @@
+2018-03-02  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/84171
+       * g++.dg/warn/Wsign-compare-8.C: New test.
+
 2018-03-02  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/84662
diff --git a/gcc/testsuite/g++.dg/warn/Wsign-compare-8.C b/gcc/testsuite/g++.dg/warn/Wsign-compare-8.C
new file mode 100644 (file)
index 0000000..237ba84
--- /dev/null
@@ -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" }