PR c/80892 - -Wfloat-conversion now warns about non-floats
authorMartin Sebor <msebor@redhat.com>
Sat, 3 Jun 2017 02:49:30 +0000 (02:49 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Sat, 3 Jun 2017 02:49:30 +0000 (20:49 -0600)
gcc/c-family/ChangeLog:

PR c/80892
* c-warn.c (conversion_warning): Use -Wconversion for integer
conversion and -Wfloat-conversion for floating one.

gcc/testsuite/ChangeLog:

PR c/80892
* c-c++-common/Wfloat-conversion-2.c: New test.

From-SVN: r248852

gcc/c-family/ChangeLog
gcc/c-family/c-warn.c
gcc/testsuite/ChangeLog

index 0d54c903d6eba9c70c459048441a952d8d86b871..569b456a72497c0b5fbfcd16044e0db4248b3fd5 100644 (file)
@@ -1,3 +1,9 @@
+2017-06-02  Martin Sebor  <msebor@redhat.com>
+
+       PR c/80892
+       * c-warn.c (conversion_warning): Use -Wconversion for integer
+       conversion and -Wfloat-conversion for floating one.
+
 2017-06-02  Bernd Edlinger  <bernd.edlinger@hotmail.de>
 
        * c.opt (Wsizeof-pointer-div): New warning option.
index 012675bf6e9ae88d1d6797f7400e79d2b8b885ef..35321a6cb1b10136e3cf4399a2a27b132d92239f 100644 (file)
@@ -1043,10 +1043,19 @@ conversion_warning (location_t loc, tree type, tree expr, tree result)
                    "conversion from %qT to to %qT discards imaginary "
                    "component",
                    expr_type, type);
-      else if (conversion_kind == UNSAFE_REAL || conversion_kind)
-       warning_at (loc, OPT_Wfloat_conversion,
-                   "conversion from %qT to %qT may change value",
-                   expr_type, type);
+      else
+       {
+         int warnopt;
+         if (conversion_kind == UNSAFE_REAL)
+           warnopt = OPT_Wfloat_conversion;
+         else if (conversion_kind)
+           warnopt = OPT_Wconversion;
+         else
+           break;
+         warning_at (loc, warnopt,
+                     "conversion from %qT to %qT may change value",
+                     expr_type, type);
+       }
     }
 }
 
index d150f8686ee02db75cd1d36776ff1135974eba51..537e6422d225dbe17b773da3faccb71f00e89dc5 100644 (file)
@@ -1,3 +1,8 @@
+2017-06-02  Martin Sebor  <msebor@redhat.com>
+
+       PR c/80892
+       * c-c++-common/Wfloat-conversion-2.c: New test.
+
 2017-06-02  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/68754