This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] use the right conversion warning option (PR c/80892)
- From: Martin Sebor <msebor at gmail dot com>
- To: Gcc Patch List <gcc-patches at gcc dot gnu dot org>, Joseph Myers <joseph at codesourcery dot com>
- Date: Tue, 30 May 2017 13:43:36 -0600
- Subject: [PATCH] use the right conversion warning option (PR c/80892)
- Authentication-results: sourceware.org; auth=none
The conversion enhancements I committed in r248431 introduced
an unintended change in which warning option is used to issue
certain integer conversion warnings. Attached is a fix.
Martin
PR c/80892 - -Wfloat-conversion now warns about non-floats
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.
diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c
index 012675b..35321a6 100644
--- a/gcc/c-family/c-warn.c
+++ b/gcc/c-family/c-warn.c
@@ -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);
+ }
}
}
diff --git a/gcc/testsuite/c-c++-common/Wfloat-conversion-2.c b/gcc/testsuite/c-c++-common/Wfloat-conversion-2.c
new file mode 100644
index 0000000..626e35b
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wfloat-conversion-2.c
@@ -0,0 +1,19 @@
+/* PR c/80892 - [8 regression] -Wfloat-conversion now warns about non-floats
+ { dg-do compile }
+ { dg-options "-Wconversion -Wfloat-conversion" }
+ { dg-require-effective-target int32plus }
+ { dg-require-effective-target double64plus } */
+
+void fschar (char);
+
+void fulong (unsigned long x)
+{
+ fschar (x); /* { dg-warning "\\[-Wconversion\\]" } */
+}
+
+void ffloat (float);
+
+void fdouble (double x)
+{
+ ffloat (x); /* { dg-warning "\\[-Wfloat-conversion\\]" } */
+}