A tiny patch for -Wsign-compare so that is also prints the types when
reporting a warning.

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

2017-07-13  Marek Polacek  <pola...@redhat.com>

        PR c/81417
        * c-warn.c (warn_for_sign_compare): Print the types.

        * c-c++-common/Wsign-compare-1.c: New test.

diff --git gcc/c-family/c-warn.c gcc/c-family/c-warn.c
index b9378c2dbe2..c903c080a33 100644
--- gcc/c-family/c-warn.c
+++ gcc/c-family/c-warn.c
@@ -1891,9 +1891,10 @@ warn_for_sign_compare (location_t location,
                                   c_common_signed_type (base_type)))
        /* OK */;
       else
-       warning_at (location,
-                   OPT_Wsign_compare,
-                   "comparison between signed and unsigned integer 
expressions");
+       warning_at (location, OPT_Wsign_compare,
+                   "comparison between signed and unsigned integer "
+                   "expressions: %qT and %qT", TREE_TYPE (sop),
+                   TREE_TYPE (uop));
     }
 
   /* Warn if two unsigned values are being compared in a size larger
diff --git gcc/testsuite/c-c++-common/Wsign-compare-1.c 
gcc/testsuite/c-c++-common/Wsign-compare-1.c
index e69de29bb2d..e53f87aa9a3 100644
--- gcc/testsuite/c-c++-common/Wsign-compare-1.c
+++ gcc/testsuite/c-c++-common/Wsign-compare-1.c
@@ -0,0 +1,27 @@
+/* PR c/81417 */
+/* { dg-do compile } */
+/* { dg-options "-Wsign-compare" } */
+
+int
+fn1 (signed int a, unsigned int b)
+{
+  return a < b; /* { dg-warning "comparison between signed and unsigned 
integer expressions: 'int' and 'unsigned int'" } */
+}
+
+int
+fn2 (signed int a, unsigned int b)
+{
+  return b < a; /* { dg-warning "comparison between signed and unsigned 
integer expressions: 'int' and 'unsigned int'" } */
+}
+
+int
+fn3 (signed long int a, unsigned long int b)
+{
+  return b < a; /* { dg-warning "comparison between signed and unsigned 
integer expressions: 'long int' and 'long unsigned int'" } */
+}
+
+int
+fn4 (signed short int a, unsigned int b)
+{
+  return b < a; /* { dg-warning "comparison between signed and unsigned 
integer expressions: 'short int' and 'unsigned int'" } */
+}

        Marek

Reply via email to