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 27cc43ee3a6cfbbad66000ecd5e86b668294c59f..fe1fc81139ed039374e0bb3876ddec9ff7d442f4 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 f3fb62c7e6285d6ce2ed44783f689e90926cbb83..7c385959c4f6f90705d76b43468bff6060f63cfe 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 0c73e80a6ff23d584babe5acc58dc439ee781b67..a848cd3f2da36ac68f007f7612b1a800677c9163 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" }